diff --git a/ui/src/app/components/json-form.directive.js b/ui/src/app/components/json-form.directive.js index 5749271c5d..b016f57d89 100644 --- a/ui/src/app/components/json-form.directive.js +++ b/ui/src/app/components/json-form.directive.js @@ -82,6 +82,7 @@ function JsonForm($compile, $templateCache, $mdColorPicker) { val = undefined; } selectOrSet(key, scope.model, val); + scope.formProps.model = scope.model; }, onColorClick: function(event, key, val) { scope.showColorPicker(event, val); diff --git a/ui/src/app/components/react/json-form-rc-select.jsx b/ui/src/app/components/react/json-form-rc-select.jsx index ffa0331d97..83fa929301 100644 --- a/ui/src/app/components/react/json-form-rc-select.jsx +++ b/ui/src/app/components/react/json-form-rc-select.jsx @@ -27,39 +27,90 @@ class ThingsboardRcSelect extends React.Component { this.onDeselect = this.onDeselect.bind(this); this.onBlur = this.onBlur.bind(this); this.onFocus = this.onFocus.bind(this); - let emptyValue = this.props.form.schema.type === 'array'? [] : null; this.state = { - currentValue: this.props.value || emptyValue, + currentValue: this.keyToCurrentValue(this.props.value, this.props.form.schema.type === 'array'), items: this.props.form.items, focused: false }; } + keyToCurrentValue(key, isArray) { + var currentValue = isArray ? [] : null; + if (isArray) { + var keys = key; + if (keys) { + for (var i = 0; i < keys.length; i++) { + currentValue.push({key: keys[i], label: this.labelFromKey(keys[i])}); + } + } + } else { + currentValue = {key: key, label: this.labelFromKey(key)}; + } + return currentValue; + } + + labelFromKey(key) { + let label = key || ''; + if (key) { + for (var i=0;i -1) { v.splice(index, 1); } this.setState({ currentValue: v }); - this.props.onChangeValidate(v); + this.props.onChangeValidate(this.arrayValues(v)); } } @@ -105,6 +156,7 @@ class ThingsboardRcSelect extends React.Component { combobox={this.props.form.combobox} disabled={this.props.form.readonly} value={this.state.currentValue} + labelInValue={true} onSelect={this.onSelect} onDeselect={this.onDeselect} onFocus={this.onFocus} diff --git a/ui/src/app/components/react/json-form-schema-form.jsx b/ui/src/app/components/react/json-form-schema-form.jsx index e006eb93d7..09712f26c5 100644 --- a/ui/src/app/components/react/json-form-schema-form.jsx +++ b/ui/src/app/components/react/json-form-schema-form.jsx @@ -63,11 +63,15 @@ class ThingsboardSchemaForm extends React.Component { this.onChange = this.onChange.bind(this); this.onColorClick = this.onColorClick.bind(this); + this.hasConditions = false; } onChange(key, val) { //console.log('SchemaForm.onChange', key, val); this.props.onModelChange(key, val); + if (this.hasConditions) { + this.forceUpdate(); + } } onColorClick(event, key, val) { @@ -81,8 +85,11 @@ class ThingsboardSchemaForm extends React.Component { console.log('Invalid field: \"' + form.key[0] + '\"!'); return null; } - if(form.condition && eval(form.condition) === false) { - return null; + if(form.condition) { + this.hasConditions = true; + if (eval(form.condition) === false) { + return null; + } } return }