2017-08-19 10:41:08 +09:00
|
|
|
import React from 'react';
|
2018-05-10 10:03:59 -04:00
|
|
|
import { intlShape } from 'meteor/vulcan:i18n';
|
2017-08-19 10:41:08 +09:00
|
|
|
import { Select } from 'formsy-react-components';
|
|
|
|
import { registerComponent } from 'meteor/vulcan:core';
|
2018-08-06 10:43:00 +09:00
|
|
|
|
|
|
|
// copied from vulcan:forms/utils.js to avoid extra dependency
|
|
|
|
const getFieldType = datatype => datatype[0].type;
|
2017-08-19 10:41:08 +09:00
|
|
|
|
2018-08-06 10:30:15 +09:00
|
|
|
const SelectComponent = ({refFunction, inputProperties, datatype, ...properties}, { intl }) => {
|
2018-05-10 10:03:59 -04:00
|
|
|
const noneOption = {
|
|
|
|
label: intl.formatMessage({ id: 'forms.select_option' }),
|
2018-08-16 12:30:33 +09:00
|
|
|
value: getFieldType(datatype) === String || getFieldType(datatype) === Number ? '' : null, // depending on field type, empty value can be '' or null
|
2018-05-10 10:03:59 -04:00
|
|
|
disabled: true,
|
|
|
|
};
|
2018-06-25 08:39:00 +02:00
|
|
|
let otherOptions = Array.isArray(inputProperties.options) && inputProperties.options.length ? inputProperties.options : [];
|
2018-06-21 10:28:34 +09:00
|
|
|
const options = [noneOption, ...otherOptions];
|
2018-06-20 10:54:02 +09:00
|
|
|
return <Select {...inputProperties} options={options} ref={refFunction}/>
|
2018-05-10 10:03:59 -04:00
|
|
|
};
|
2017-08-19 10:41:08 +09:00
|
|
|
|
2018-05-10 10:03:59 -04:00
|
|
|
SelectComponent.contextTypes = {
|
|
|
|
intl: intlShape,
|
|
|
|
};
|
|
|
|
|
|
|
|
registerComponent('FormComponentSelect', SelectComponent);
|