Commit 7bc1e2c58efe36eb798ef4a15758f77a526d68a1

Authored by Igor Kulikov
1 parent 87ade8ad

JSON form component improvements. Fix timewindow panel

... ... @@ -104,6 +104,7 @@ export class JsonFormComponent implements OnInit, ControlValueAccessor, Validato
104 104 fullscreenFinishFn: () => void;
105 105
106 106 private propagateChange = null;
  107 + private propagateChangePending = false;
107 108
108 109 constructor(public elementRef: ElementRef,
109 110 private translate: TranslateService,
... ... @@ -120,6 +121,12 @@ export class JsonFormComponent implements OnInit, ControlValueAccessor, Validato
120 121
121 122 registerOnChange(fn: any): void {
122 123 this.propagateChange = fn;
  124 + if (this.propagateChangePending) {
  125 + this.propagateChangePending = false;
  126 + setTimeout(() => {
  127 + this.propagateChange(this.data);
  128 + }, 0);
  129 + }
123 130 }
124 131
125 132 registerOnTouched(fn: any): void {
... ... @@ -154,7 +161,11 @@ export class JsonFormComponent implements OnInit, ControlValueAccessor, Validato
154 161 updateView() {
155 162 if (this.data) {
156 163 this.data.model = this.model;
157   - this.propagateChange(this.data);
  164 + if (this.propagateChange) {
  165 + this.propagateChange(this.data);
  166 + } else {
  167 + this.propagateChangePending = true;
  168 + }
158 169 }
159 170 }
160 171
... ...
... ... @@ -33,9 +33,9 @@ export default ThingsboardBaseComponent => class<P extends JsonFormFieldProps>
33 33 }
34 34
35 35 componentDidMount() {
36   - /* if (typeof this.state.value !== 'undefined') {
  36 + if (typeof this.state.value !== 'undefined') {
37 37 this.props.onChange(this.props.form.key, this.state.value);
38   - }*/
  38 + }
39 39 }
40 40
41 41 onChangeValidate(e, forceUpdate?: boolean) {
... ...
... ... @@ -28,7 +28,7 @@ class ThingsboardCheckbox extends React.Component<JsonFormFieldProps, JsonFormFi
28 28 <Checkbox
29 29 name={this.props.form.key.slice(-1)[0] + ''}
30 30 value={this.props.form.key.slice(-1)[0]}
31   - defaultChecked={this.props.value || false}
  31 + checked={this.props.value || false}
32 32 disabled={this.props.form.readonly}
33 33 onChange={(e, checked) => {
34 34 this.props.onChangeValidate(e);
... ...
... ... @@ -134,11 +134,6 @@ $previewSize: 100px !default;
134 134 display: none;
135 135 }
136 136
137   - span.tb-toggle-icon {
138   - padding-top: 12px;
139   - padding-bottom: 12px;
140   - }
141   -
142 137 .tb-button-toggle .tb-toggle-icon {
143 138 display: inline-block;
144 139 width: 15px;
... ...
... ... @@ -103,7 +103,6 @@
103 103 predefinedName="aggregation.group-interval">
104 104 </tb-timeinterval>
105 105 </div>
106   - <span fxFlex></span>
107 106 <div fxLayout="row" class="tb-panel-actions">
108 107 <span fxFlex></span>
109 108 <button type="submit"
... ...