EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: tomhj on July 19, 2012, 10:25:52 PM



Title: How to make a text field in datagrid 'required'?
Post by: tomhj on July 19, 2012, 10:25:52 PM
I have a treegrid with editable columns with types 'combobox', 'text', and 'checkbox'.  The combobox and text fields are required.  I can specify through the editor for the combobox and the options property that the field is required: true.  But I don't see how to make the text field 'required'.  The 'options' property seems to be ignored for that editor type.

Am I missing something? 


Title: Re: How to make a text field in datagrid 'required'?
Post by: stworthy on July 19, 2012, 11:05:49 PM
The 'text' editor is a simple textbox. To use additional editing options, please use the 'validatebox' editor:
Code:
columns:[[
{field:'name',title:'Name',width:120,
editor:{
type:'validatebox',
options:{
required:true
}
}
},
...
]]


Title: Re: How to make a text field in datagrid 'required'?
Post by: tomhj on July 19, 2012, 11:14:49 PM
Thanks - that works.  One odd thing though:  when the row switches into edit mode, the combobox immediately shows the "this field is required" icon but the text/validatebox field doesn't show it until that field has the focus.  Is that normal/expected behavior?


Title: Re: How to make a text field in datagrid 'required'?
Post by: stworthy on July 20, 2012, 01:29:04 AM
When edit a row, all the empty field with 'required' property will display an alert icon on right of textbox. When move the mouse over the empty field with 'required' property, the 'this field is required' message will show immediately.


Title: Re: How to make a text field in datagrid 'required'?
Post by: tomhj on July 20, 2012, 08:23:46 AM
That's what I was expecting, but it isn't what I'm seeing.  The newly inserted row shows the red triangle icon in the required combobox field but not the validatebox field.  The red triangle icon doesn't show in empty the validatebox field until I click in that edit box - then it stays there until I enter a value.

Here is the field definition for that column:

{field: 'name', title: 'Name', width:150, sortable:true, resizable:true, editor: { type: 'validatebox', options: {required: true}}}


Title: Re: How to make a text field in datagrid 'required'?
Post by: tomhj on July 20, 2012, 10:00:06 AM
I figured out the problem - there was another column/field with a formatter that wasn't properly handling the field value being undefined.