Merge pull request #637 from ONLYOFFICE/fix/de-forms

Fix/de forms
This commit is contained in:
Julia Radzhabova 2020-12-25 12:34:08 +03:00 committed by GitHub
commit e630654173
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 21 deletions

View file

@ -161,11 +161,12 @@ define([
if (e.isDefaultPrevented()) if (e.isDefaultPrevented())
return; return;
if (e.keyCode === Common.UI.Keys.RETURN) if (e.keyCode === Common.UI.Keys.RETURN) {
this._doChange(e); e.stopPropagation();
}
if (e.keyCode == Common.UI.Keys.ESC) if (e.keyCode == Common.UI.Keys.ESC)
this.setValue(this.value); this.setValue(this.value);
if (e.keyCode==Common.UI.Keys.RETURN || e.keyCode==Common.UI.Keys.ESC) if (e.keyCode==Common.UI.Keys.ESC)
this.trigger('inputleave', this); this.trigger('inputleave', this);
}, },

View file

@ -212,8 +212,8 @@ define([
value : '' value : ''
}); });
this.lockedControls.push(this.txtNewValue); this.lockedControls.push(this.txtNewValue);
this.txtNewValue.on('changed:after', this.onAddItem.bind(this));
this.txtNewValue.on('inputleave', function(){ me.fireEvent('editcomplete', me);}); this.txtNewValue.on('inputleave', function(){ me.fireEvent('editcomplete', me);});
this.txtNewValue._input.on('keydown', _.bind(this.onNewValueKeydown, this));
this.list = new Common.UI.ListView({ this.list = new Common.UI.ListView({
el: $markup.findById('#form-list-list'), el: $markup.findById('#form-list-list'),
@ -341,22 +341,24 @@ define([
}, },
onPlaceholderChanged: function(input, newValue, oldValue, e) { onPlaceholderChanged: function(input, newValue, oldValue, e) {
if (this.api && !this._noApply) { if (this.api && !this._noApply && (newValue!==oldValue)) {
var props = this._originalProps || new AscCommon.CContentControlPr(); var props = this._originalProps || new AscCommon.CContentControlPr();
props.put_PlaceholderText(newValue || ' '); props.put_PlaceholderText(newValue || ' ');
this.api.asc_SetContentControlProperties(props, this.internalId); this.api.asc_SetContentControlProperties(props, this.internalId);
this.fireEvent('editcomplete', this); if (!e.relatedTarget || (e.relatedTarget.localName != 'input' && e.relatedTarget.localName != 'textarea') || !/form-control/.test(e.relatedTarget.className))
this.fireEvent('editcomplete', this);
} }
}, },
onHelpChanged: function(input, newValue, oldValue, e) { onHelpChanged: function(input, newValue, oldValue, e) {
if (this.api && !this._noApply) { if (this.api && !this._noApply && (newValue!==oldValue)) {
var props = this._originalProps || new AscCommon.CContentControlPr(); var props = this._originalProps || new AscCommon.CContentControlPr();
var formPr = this._originalFormProps || new AscCommon.CSdtFormPr(); var formPr = this._originalFormProps || new AscCommon.CSdtFormPr();
formPr.put_HelpText(newValue); formPr.put_HelpText(newValue);
props.put_FormPr(formPr); props.put_FormPr(formPr);
this.api.asc_SetContentControlProperties(props, this.internalId); this.api.asc_SetContentControlProperties(props, this.internalId);
this.fireEvent('editcomplete', this); if (!e.relatedTarget || (e.relatedTarget.localName != 'input' && e.relatedTarget.localName != 'textarea') || !/form-control/.test(e.relatedTarget.className))
this.fireEvent('editcomplete', this);
} }
}, },
@ -455,6 +457,12 @@ define([
} }
}, },
onNewValueKeydown: function(event) {
if (this.api && !this._noApply && event.keyCode == Common.UI.Keys.RETURN) {
this.onAddItem();
}
},
onAddItem: function() { onAddItem: function() {
var store = this.list.store, var store = this.list.store,
value = this.txtNewValue.getValue(); value = this.txtNewValue.getValue();
@ -645,14 +653,20 @@ define([
this.labelFormName.text(this.textImage); this.labelFormName.text(this.textImage);
} else } else
data = this.api.asc_GetTextFormKeys(); data = this.api.asc_GetTextFormKeys();
var arr = []; if (!this._state.arrKey || _.difference(this._state.arrKey, data).length>0) {
data.forEach(function(item) { var arr = [];
arr.push({ displayValue: item, value: item }); data.forEach(function(item) {
}); arr.push({ displayValue: item, value: item });
this.cmbKey.setData(arr); });
this.cmbKey.setData(arr);
this._state.arrKey=data;
}
val = formPr.get_Key(); val = formPr.get_Key();
this.cmbKey.setValue(val ? val : ''); if (this._state.Key!==val) {
this.cmbKey.setValue(val ? val : '');
this._state.Key=val;
}
if (val) { if (val) {
val = this.api.asc_GetFormsCountByKey(val); val = this.api.asc_GetFormsCountByKey(val);
@ -670,12 +684,20 @@ define([
val = specProps.get_GroupKey(); val = specProps.get_GroupKey();
var ischeckbox = (typeof val !== 'string'); var ischeckbox = (typeof val !== 'string');
if (!ischeckbox) { if (!ischeckbox) {
var arr = []; data = this.api.asc_GetRadioButtonGroupKeys();
this.api.asc_GetRadioButtonGroupKeys().forEach(function(item) { if (!this._state.arrGroupKey || _.difference(this._state.arrGroupKey, data).length>0) {
arr.push({ displayValue: item, value: item }); var arr = [];
}); data.forEach(function(item) {
this.cmbGroupKey.setData(arr); arr.push({ displayValue: item, value: item });
this.cmbGroupKey.setValue(val ? val : ''); });
this.cmbGroupKey.setData(arr);
this._state.arrGroupKey=data;
}
if (this._state.groupKey!==val) {
this.cmbGroupKey.setValue(val ? val : '');
this._state.groupKey=val;
}
} }
this.labelFormName.text(ischeckbox ? this.textCheckbox : this.textRadiobox); this.labelFormName.text(ischeckbox ? this.textCheckbox : this.textRadiobox);
@ -711,7 +733,10 @@ define([
val = formTextPr.get_MaxCharacters(); val = formTextPr.get_MaxCharacters();
this.chMaxChars.setValue(val && val>=0); this.chMaxChars.setValue(val && val>=0);
this.spnMaxChars.setDisabled(!val || val<0); this.spnMaxChars.setDisabled(!val || val<0);
this.spnMaxChars.setValue(val && val>=0 ? val : 10); if ( (val===undefined || this._state.MaxChars===undefined)&&(this._state.MaxChars!==val) || Math.abs(this._state.MaxChars-val)>0.1) {
this.spnMaxChars.setValue(val && val>=0 ? val : 10, true);
this._state.MaxChars=val;
}
var brd = formTextPr.get_CombBorder(); var brd = formTextPr.get_CombBorder();
if (brd) { if (brd) {