Setting Text Field Attribute: 'required'
Setting Text Field Attribute: 'required'

Hi,
Referring to:
https://editor.datatables.net/reference/field/text
The document suggests that input attributes are set with the attr object which expects key / value pairs. This works well for 'maxlength' and 'placeholder':
fields: [
{
label: "test:",
name: "test",
type: "text",
attr: {
maxlength: '5',
placeholder: 'test input',
required: ?????????????????
}
}
]
However attribute 'required' does not exist as an attribute/value pair in the same way. I want to achieve the following:
<input name="test" maxlength="5" placeholder="test input" required>
How should I set the attr object to achieve an input with 'required' as above?
Steve
This question has accepted answers - jump to:
Answers
There is a "required" validator for Editor fields.
https://editor.datatables.net/manual/php/validation
I've just tried it here and it seems to work as expected. Since its an HTML attribute you could also use
required
(i.e. as a string).Allan
The demo code doesn't work, currently!!
Why??
@Jack Ting , which demo code is that? Can you give more information, please?
The example given by @allan is not working correctly. I can still add new entries to the table without filling out the required fields.
Hi @elias.sa ,
Ah, I see. It seems it's honouring the other HTML attributes, see here, it just seems to have an issue with
required
. I've raised it internally (DD-891 for my reference) and we'll report back here when there's an update.Cheers,
Colin
It is actually being set in the demo I have above, but there is no validation on the form, which is why it is effectively ignored. You need to use server-side validation (or
initSubmit
/preSubmit
) even if you want to do client-side validation.Allan