Form Helpers
OPAL comes with a selection of templatetags that can help you with the repetitive task of generating Bootstrap and OPAL compatible markup for your forms.
{% checkbox ... %}
Generates a checkbox
Keywords:
fielda string of the model name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% checkbox field="DogOwner.dog" %}labelThe Label with which to describe this fieldmodelThe model which we are editing (This is a string that references an in-scope Angular variable)disabledIf this exists, we use this as the expression for the ng-disabled directive
{% datepicker ... %}
Generates a datepicker
Keywords:
fielda string of the models api name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% datepicker field="DogOwner.dog" %}labelThe Label with which to describe this fieldmodelThe model which we are editing (This is a string that references an in-scope Angular variable)showA string that contains an Angular expression for the ng-show directivehideA string that contains an Angular expression for the ng-hide directiverequiredLabel to show when we're requiredmindateExpression to use to set the minimum possible date
{% datepicker ... %}
Generates a date time fields, a date field on one line and a time field on another
Keywords:
fielda string of the models api name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% datetimepicker field="DogOwner.vet_appointment" %}date_labelThe Label with which to describe the date field (defaults to 'Date')time_labelThe Label with which to describe the date field (defaults to 'Time')modelThe model which we are editing (This is a string that references an in-scope Angular variable)changean angular directive that fires on change
{% input ... %}
The input template tag generates you a form input that will play nicely with OPAL's styling.
Keywords:
fielda string of the models api name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% input field="DogOwner.dog" %}labelThe Label with which to describe this fieldmodelThe model which we are editing (This is a string that references an in-scope Angular variable)showA string that contains an Angular expression for the ng-show directivehideA string that contains an Angular expression for the ng-hide directivelookuplistan Angular expression that evaluates to an array containing the lookuplist valuesrequiredLabel to show when we're requiredenterexpression to evaluate if the user presses return when in this inputmaxlengthmaximum number of characters for this input. Will render the form invalid and display help text if exceeded.statican Angular expression that will swap the display to be a static input if it evaluates totrue
Inputs for subrecord fields
A very common pattern is to render form fields that relate to fields of Subrecords. The input templatetag
accepts a field argument, from which it will infer the label, model and lookuplist by introspecting the relevant subrecord model.
{% input field="allergies.drug" %}
Inputs with units
We also often want to display the unit of a particular field to help our users - consistent styling for this is available by using the unit argument e.g.
{% input label="Weight" model="editing.weight" unit="kg" %}
{% radio ... %}
Generates an inline radio input
Keywords:
fielda string of the models api name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% radio field="DogOwner.dog" %}labelThe Label with which to describe this inputmodelThe model which we are editing (This is a string that references an in-scope Angular variable)showA string that contains an Angular expression for the ng-show directivehideA string that contains an Angular expression for the ng-hide directivelookuplistan Angular expression that evaluates to an array containing the radio values
{% select ... %}
Generates an inline select input
Keywords:
fielda string of the models api name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% select field="DogOwner.dog" %}labelThe Label with which to describe this inputmodelThe model which we are editing (This is a string that references an in-scope Angular variable)showA string that contains an Angular expression for the ng-show directivehideA string that contains an Angular expression for the ng-hide directivelookuplistan Angular expression that evaluates to an array containing the radio valuesotherA boolean parameter that if true, provides a free text option when 'Other' is selectedhelpa template to use as the contents of a help popoverstatican Angular expression that will swap the display to be a static input if it evaluates totrue*
{% textarea ... %}
Generates an inline textarea input
Keywords:
fielda string of the models api name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% textarea field="DogOwner.dog" %}labelThe Label with which to describe this inputmodelThe model which we are editing (This is a string that references an in-scope Angular variable)showA string that contains an Angular expression for the ng-show directivehideA string that contains an Angular expression for the ng-hide directive
{% static ... %}
Generates a bootstrap Static div (for displaying data from fields as uneditable but formatted nicely with appropriate styles).
Takes one positional argument, a string representing the subrecord field path.
{% static "Demographics.name" %}
<!-- Renders as -->
<div class="form-group">
<label class="control-label col-sm-3">
Name
</label>
<p class="form-control-static col-sm-8">
[[ editing.demographics.name ]]
</p>
</div>
{% icon "icon-name" %}
Renders a Bootstrap style Icon tag.
If the icon starts with fa or glyphicon then we will insert the preceding fa.
{% icon "fa-user-md" %}
<i class="fa fa-user-md"></i>
{% icon "cusom-icon"}
<i class="custom-icon"></i>