cliveportman/code

Add required attribute to form inputs in Craft CMS control panel plugin templates

Warning! I had to undo the edits below when adding custom fields to entry types in the control panel using the drag and drop editor. So treat them with caution...

This doesn't seem to be supported out of the box, but can be done with a quick edit to the respective fieldtypes within craft/app/templates/_includes/forms/. I suspect it'll need re-doing every update, which isn't ideal.

To make a text field required, for example, open up craft/app/templates/_includes/forms/text.html and add the following line around where similar lines exist:

{%- if required is defined and required %} required {% endif %}

Then, when calling for the field in your control panel templates, use:

{{ forms.text( {
    id: 'schoolname',
    name: 'title',
    value : school.title | default,
    placeholder : 'e.g. Name of school',
    required: TRUE
 } ) }}

For more information on adding fields I've written more here.