admin管理员组文章数量:1426929
In Jqgrid you apply a required attribute to any given field like this
{ name: 'Comments', index: 'Comments', editable: true, editrules: { required: true }, edittype: 'textarea' }
How would I go about doing this dynamically? I'd like to make a field required, based on another field (like the selected value of a dropdown/bobox)
I know where to place the code, eg, my dropdown's select event. But not how to apply the required attribute in any other way other than the code sample I supplied..
In Jqgrid you apply a required attribute to any given field like this
{ name: 'Comments', index: 'Comments', editable: true, editrules: { required: true }, edittype: 'textarea' }
How would I go about doing this dynamically? I'd like to make a field required, based on another field (like the selected value of a dropdown/bobox)
I know where to place the code, eg, my dropdown's select event. But not how to apply the required attribute in any other way other than the code sample I supplied..
Share Improve this question edited Jul 23, 2015 at 9:21 Rohan Büchner asked Apr 23, 2012 at 7:11 Rohan BüchnerRohan Büchner 5,4035 gold badges65 silver badges106 bronze badges1 Answer
Reset to default 6I suggest that you use some event to monitor the changes in the select control and change the value of the required
option of editrules.
For example in the demo I used 'focusout' event on the select control of 'ship_via' column to change the required
option of editrules of the column 'note'. I used the 'focusout' event because the code used the bug fix which I suggested here. You can use other events alternatively, but you should test there in different browsers.
The code which I used in the demo is
{name: 'ship_via', index: 'ship_via', width: 105, align: 'center', editable: true,
formatter: 'select', edittype: 'select', editoptions: {
value: 'FE:FedEx;TN:TNT;IN:Intim',
defaultValue: 'IN',
dataEvents: [
{
type: 'focusout',
fn: function (e) {
$grid.jqGrid('setColProp', 'note', {
editrules: {required: ($(e.target).val() !== "IN")}
});
}
}
]
},
stype: 'select', searchoptions: {
sopt: ['eq', 'ne'],
value: ':Any;FE:FedEx;TN:TNT;IN:IN'
} },
{ name: 'note', index: 'note', width: 60, sortable: false, editable: true,
edittype: 'textarea' }
本文标签: javascriptApply Jqgrid required attribute dynamicallyStack Overflow
版权声明:本文标题:javascript - Apply Jqgrid required attribute dynamically - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745407038a2657297.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论