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';
|
2019-01-26 21:21:09 +09:00
|
|
|
import Form from 'react-bootstrap/lib/Form';
|
2019-01-24 18:01:53 +09:00
|
|
|
import { Components, registerComponent } from 'meteor/vulcan:core';
|
2018-08-06 10:43:00 +09:00
|
|
|
|
|
|
|
// copied from vulcan:forms/utils.js to avoid extra dependency
|
2018-08-17 13:49:15 +09:00
|
|
|
const getFieldType = datatype => datatype && datatype[0].type;
|
2017-08-19 10:41:08 +09:00
|
|
|
|
2019-01-24 18:01:53 +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,
|
|
|
|
};
|
2019-01-24 18:01:53 +09:00
|
|
|
let otherOptions =
|
|
|
|
Array.isArray(inputProperties.options) && inputProperties.options.length
|
|
|
|
? inputProperties.options
|
|
|
|
: [];
|
2018-06-21 10:28:34 +09:00
|
|
|
const options = [noneOption, ...otherOptions];
|
2019-01-24 18:01:53 +09:00
|
|
|
return (
|
|
|
|
<Components.FormItem {...inputProperties}>
|
|
|
|
<Form.Control as="select" {...inputProperties} ref={refFunction}>
|
|
|
|
{options.map((option, i) => (
|
|
|
|
<option key={i} {...option}>{option.value}</option>
|
|
|
|
))}
|
|
|
|
</Form.Control>
|
|
|
|
</Components.FormItem>
|
|
|
|
);
|
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);
|