I want to use values from annotation in CRUD module templates, to utilize HTML5 functions.
e.g.
@Range(min=0, max=10)
public int size;
CRUD module use views/tags/crud/numberField.html to display number field:
#{field 'object.' + _name}
<label for="${field.id}">
&{_name}
</label>
<input id="${field.id}" type="text" name="${field.name}" value="${params[field.name]?.escape()?.raw() ?: field.error?.message == 'validation.required' ? '' : _value?.escape()?.raw()}" size="5" />
#{ifError field.name}
<span class="error">${field.error}</span>
#{/ifError}
#{/field}
How can I read min/max value from annotation then output as min=”0″ max=”0″ in <input> ?
You can do this by adding methods to the CRUD module’s
CRUD.ObjectType.ObjectFieldinner class that read the annotation values, e.g. something like:Then in
crud/views/tags/crud/form.htmlyou can use this in a new tag parameter inside the#{if field.type == 'number'}(note thatfieldis aCRUD.ObjectType.ObjectFieldhere:The value is then available as
_mininside thenumberField.htmltag.