Add the method of auto-filling some input boxes to the Form of EasyUi, easyuiform
According to the project requirements, some input boxes of Form are filled Based on the obtained data. However, the default EasyUI Form does not have this method, and only one input box can be directly assigned a value, therefore, the setValues of the Form object is added to implement the filling function based on the given Id. The Code is as follows:
$.extend($.fn.form.methods, { setValues: function (myself, data) { var form = $(myself); var opts = $.data(form[0], "form").options; var cols = "," + data.items + ","; for (var name in data.row) { if (cols.indexOf(name) >= 0) { var val = data.row[name]; form.find("[id=\"" + name + "\"]").textbox("setValue",val); } } opts.onLoadSuccess.call(form, data); form.form("validate"); }});An example of the above Code is as follows:
Function reply () {var row = $ ('# feedbackGrid '). datagrid ('getselected'); if (row) {$ ('# feedbackdlg '). dialog ('open '). dialog ('settitle', 'feedback response'); var obj ={}; obj. row = row; obj. items = "nickName, userId"; $ ('# fm '). form ('setvalues', obj); url = 'feedback/reply ';}}As described above, the parameters passed in the setValues method are divided into two elements: row, which contains the actual data object, and items, which contains the id of the HTML object to be filled, multiple IDs are separated by commas.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.