From ace3bd1cd175b8285e20933c004e7c5aa826028a Mon Sep 17 00:00:00 2001 From: Alan Date: Fri, 23 Sep 2022 11:41:07 +0800 Subject: [PATCH] Fix #7418 - radio button set value --- Roo/form/BasicForm.js | 8 ++++- Roo/form/Checkbox.js | 4 ++- Roo/form/Radio.js | 42 +++++++++++++++++++++- docs/json/roodata.json | 6 ++-- docs/src/Roo_form_BasicForm.js.html | 8 ++++- docs/src/Roo_form_Checkbox.js.html | 4 ++- docs/src/Roo_form_Radio.js.html | 42 +++++++++++++++++++++- docs/symbols/Roo.form.BasicForm.json | 2 +- docs/symbols/Roo.form.Form.json | 2 +- docs/symbols/Roo.form.Radio.json | 2 +- roojs-all.js | 7 ++-- roojs-debug.js | 54 ++++++++++++++++++++++++++-- roojs-ui-debug.js | 54 ++++++++++++++++++++++++++-- roojs-ui.js | 7 ++-- 14 files changed, 218 insertions(+), 24 deletions(-) diff --git a/Roo/form/BasicForm.js b/Roo/form/BasicForm.js index 67472d0d1a..130319acb0 100644 --- a/Roo/form/BasicForm.js +++ b/Roo/form/BasicForm.js @@ -507,6 +507,9 @@ clientValidation Boolean Applies to submit only. Pass true to call fo for(id in values){ if(typeof values[id] != 'function' && (field = this.findField(id))){ + + + if (field.setFromData && field.valueField && field.displayField && @@ -521,6 +524,9 @@ clientValidation Boolean Applies to submit only. Pass true to call fo sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name]; field.setFromData(sd); + } else if (field.inputType && field.inputType == 'radio') { + + field.setValue(values[id]); } else { field.setValue(values[id]); } @@ -546,7 +552,7 @@ clientValidation Boolean Applies to submit only. Pass true to call fo /** * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name * they are returned as an array. - * @param {Boolean} asString (default false) + * @param {Boolean} asString (def) * @return {Object} */ getValues : function(asString) diff --git a/Roo/form/Checkbox.js b/Roo/form/Checkbox.js index 7093fdd57f..634c5101a8 100644 --- a/Roo/form/Checkbox.js +++ b/Roo/form/Checkbox.js @@ -190,7 +190,9 @@ Roo.extend(Roo.form.Checkbox, Roo.form.Field, { this.fireEvent('check', this, state); } this.inSetChecked = true; - this.el.dom.value = state ? this.inputValue : this.valueOff; + + this.el.dom.value = state ? this.inputValue : this.valueOff; + this.inSetChecked = false; }, diff --git a/Roo/form/Radio.js b/Roo/form/Radio.js index 4f83f53a7e..974e543781 100644 --- a/Roo/form/Radio.js +++ b/Roo/form/Radio.js @@ -60,7 +60,47 @@ Roo.extend(Roo.form.Radio, Roo.form.Checkbox, { this.el.dom.checked = 'checked' ; } + }, + /** + * Sets the checked state of the checkbox. + * On is always based on a string comparison between inputValue and the param. + * @param {Boolean/String} value - the value to set + * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event. + */ + setValue : function(v,suppressEvent){ + + + //this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on'); + //if(this.el && this.el.dom){ + // this.el.dom.checked = this.checked; + // this.el.dom.defaultChecked = this.checked; + //} + this.setChecked(String(v) === String(this.inputValue), suppressEvent); + + this.el.dom.form[this.name].value = v; + + //this.fireEvent("check", this, this.checked); + }, + // private.. + setChecked : function(state,suppressEvent) + { + + if(this.wrap){ + this.wrap[state ? 'addClass' : 'removeClass']('x-menu-item-checked'); + } + this.checked = state; + if(suppressEvent !== true){ + this.fireEvent('check', this, state); + } + + + + + }, + reset : function(){ + // this.setValue(this.resetValue); + //this.originalValue = this.getValue(); + this.clearInvalid(); } - }); \ No newline at end of file diff --git a/docs/json/roodata.json b/docs/json/roodata.json index 3c8a71cb12..1914e1dd02 100644 --- a/docs/json/roodata.json +++ b/docs/json/roodata.json @@ -216152,7 +216152,7 @@ { "name" : "asString", "type" : "Boolean", - "desc" : "", + "desc" : "(def)", "isOptional" : false } ], @@ -244914,7 +244914,7 @@ { "name" : "asString", "type" : "Boolean", - "desc" : "", + "desc" : "(def)", "isOptional" : false } ], @@ -259821,7 +259821,7 @@ "desc" : "Sets the checked state of the checkbox.\nOn is always based on a string comparison between inputValue and the param.", "sig" : "(value, suppressEvent)", "static" : false, - "memberOf" : "Roo.form.Checkbox", + "memberOf" : "", "isStatic" : false, "isConstructor" : false, "isPrivate" : false, diff --git a/docs/src/Roo_form_BasicForm.js.html b/docs/src/Roo_form_BasicForm.js.html index 1210410928..3573f10ff8 100644 --- a/docs/src/Roo_form_BasicForm.js.html +++ b/docs/src/Roo_form_BasicForm.js.html @@ -507,6 +507,9 @@ clientValidation Boolean Applies to submit only. Pass true to call fo for(id in values){ if(typeof values[id] != 'function' && (field = this.findField(id))){ + + + if (field.setFromData && field.valueField && field.displayField && @@ -521,6 +524,9 @@ clientValidation Boolean Applies to submit only. Pass true to call fo sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name]; field.setFromData(sd); + } else if (field.inputType && field.inputType == 'radio') { + + field.setValue(values[id]); } else { field.setValue(values[id]); } @@ -546,7 +552,7 @@ clientValidation Boolean Applies to submit only. Pass true to call fo /** * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name * they are returned as an array. - * @param {Boolean} asString + * @param {Boolean} asString (def) * @return {Object} */ getValues : function(asString) diff --git a/docs/src/Roo_form_Checkbox.js.html b/docs/src/Roo_form_Checkbox.js.html index 39096f0cb5..b22a8e7d8f 100644 --- a/docs/src/Roo_form_Checkbox.js.html +++ b/docs/src/Roo_form_Checkbox.js.html @@ -190,7 +190,9 @@ this.fireEvent('check', this, state); } this.inSetChecked = true; - this.el.dom.value = state ? this.inputValue : this.valueOff; + + this.el.dom.value = state ? this.inputValue : this.valueOff; + this.inSetChecked = false; }, diff --git a/docs/src/Roo_form_Radio.js.html b/docs/src/Roo_form_Radio.js.html index 31049d3915..d1feaf9507 100644 --- a/docs/src/Roo_form_Radio.js.html +++ b/docs/src/Roo_form_Radio.js.html @@ -60,7 +60,47 @@ this.el.dom.checked = 'checked' ; } - } + }, + /** + * Sets the checked state of the checkbox. + * On is always based on a string comparison between inputValue and the param. + * @param {Boolean/String} value - the value to set + * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event. + */ + setValue : function(v,suppressEvent){ + + + //this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on'); + //if(this.el && this.el.dom){ + // this.el.dom.checked = this.checked; + // this.el.dom.defaultChecked = this.checked; + //} + this.setChecked(String(v) === String(this.inputValue), suppressEvent); + + this.el.dom.form[this.name].value = v; + + //this.fireEvent("check", this, this.checked); + }, + // private.. + setChecked : function(state,suppressEvent) + { + if(this.wrap){ + this.wrap[state ? 'addClass' : 'removeClass']('x-menu-item-checked'); + } + this.checked = state; + if(suppressEvent !== true){ + this.fireEvent('check', this, state); + } + + + + + }, + reset : function(){ + // this.setValue(this.resetValue); + //this.originalValue = this.getValue(); + this.clearInvalid(); + } }); \ No newline at end of file diff --git a/docs/symbols/Roo.form.BasicForm.json b/docs/symbols/Roo.form.BasicForm.json index f220c778f8..abd6d5f199 100644 --- a/docs/symbols/Roo.form.BasicForm.json +++ b/docs/symbols/Roo.form.BasicForm.json @@ -286,7 +286,7 @@ { "name" : "asString", "type" : "Boolean", - "desc" : "", + "desc" : "(def)", "isOptional" : false } ], diff --git a/docs/symbols/Roo.form.Form.json b/docs/symbols/Roo.form.Form.json index 75d14e3f19..5d461f7454 100644 --- a/docs/symbols/Roo.form.Form.json +++ b/docs/symbols/Roo.form.Form.json @@ -808,7 +808,7 @@ { "name" : "asString", "type" : "Boolean", - "desc" : "", + "desc" : "(def)", "isOptional" : false } ], diff --git a/docs/symbols/Roo.form.Radio.json b/docs/symbols/Roo.form.Radio.json index 49fc78890f..d41ae41913 100644 --- a/docs/symbols/Roo.form.Radio.json +++ b/docs/symbols/Roo.form.Radio.json @@ -317,7 +317,7 @@ "desc" : "Sets the checked state of the checkbox.\nOn is always based on a string comparison between inputValue and the param.", "sig" : "(value, suppressEvent)", "static" : false, - "memberOf" : "Roo.form.Checkbox", + "memberOf" : "", "isStatic" : false, "isConstructor" : false, "isPrivate" : false, diff --git a/roojs-all.js b/roojs-all.js index c6f920e518..cac12bf133 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -1852,7 +1852,8 @@ this.el.on('DOMAttrModified',this.setFromHidden,this);this.el.on('propertychange // Roo/form/Radio.js Roo.form.Radio=function(){Roo.form.Radio.superclass.constructor.apply(this,arguments);};Roo.extend(Roo.form.Radio,Roo.form.Checkbox,{inputType:'radio',getGroupValue:function(){return this.el.up('form').child('input[name='+this.el.dom.name+']:checked',true).value; },onRender:function(ct,A){Roo.form.Checkbox.superclass.onRender.call(this,ct,A);if(this.inputValue!==undefined){this.el.dom.value=this.inputValue;}this.wrap=this.el.wrap({cls:"x-form-check-wrap"});if(this.boxLabel){this.wrap.createChild({tag:'label',htmlFor:this.el.id,cls:'x-form-cb-label',html:this.boxLabel} -);}if(this.checked){this.el.dom.checked='checked';}}}); +);}if(this.checked){this.el.dom.checked='checked';}},setValue:function(v,A){this.setChecked(String(v)===String(this.inputValue),A);this.el.dom.form[this.name].value=v;},setChecked:function(A,B){if(this.wrap){this.wrap[A?'addClass':'removeClass']('x-menu-item-checked'); +}this.checked=A;if(B!==true){this.fireEvent('check',this,A);}},reset:function(){this.clearInvalid();}}); // Roo/rtf/namespace.js Roo.rtf={}; // Roo/rtf/Hex.js @@ -2240,8 +2241,8 @@ this.fireEvent('actioncomplete',this,A);}else{if((typeof(A.result)!='undefined') }this.childForms.push(A);var n='';Roo.each(A.allItems,function(fe){n=typeof(fe.getName)=='undefined'?fe.name:fe.getName();if(this.findField(n)){return;}var B=new Roo.form.Hidden({name:n});B.render(this.el);this.add(B);},this);},markInvalid:function(A){if(A instanceof Array){for(var i=0,B=A.length; i