Browse Source

Merge pull request #21 from xafizoff/input-required

Add "required" attribute to the "input" tag
Namdak Tonpa 6 years ago
parent
commit
372ab59da9
2 changed files with 2 additions and 1 deletions
  1. 1 1
      include/nitro.hrl
  2. 1 0
      src/elements/element_input.erl

+ 1 - 1
include/nitro.hrl

@@ -64,7 +64,7 @@
 -record(textarea,       {?ELEMENT_BASE(element_textarea), autofocus, cols, dirname, disabled, form, maxlength, name, placeholder, readonly, required, rows, wrap, value}).
 
 % HTML Form inputs
--record(input,       {?ELEMENT_BASE(element_input),  autofocus, disabled, form, name, value, type=[], placeholder, multiple, min, max, pattern, accept}).
+-record(input,       {?ELEMENT_BASE(element_input), required, autofocus, disabled, form, name, value, type=[], placeholder, multiple, min, max, pattern, accept}).
 -record(input_button,       {?ELEMENT_BASE(element_input_button),  autofocus, disabled, form, name, value}).
 -record(checkbox,           {?ELEMENT_BASE(element_checkbox),  autofocus, checked=false, disabled, form, name, required, value}).
 -record(color,           {?ELEMENT_BASE(element_color),  autocomplete, autofocus, disabled, form, list, name, value}).

+ 1 - 0
src/elements/element_input.erl

@@ -46,6 +46,7 @@ render_element(Record) ->
       {<<"onkeyup">>, Record#input.onkeyup},
       {<<"onkeydown">>, Record#input.onkeydown},
       {<<"onclick">>, Record#input.onclick},
+      {<<"required">>, if Record#input.required == true -> "required"; true -> undefined end},
       {<<"onchange">>, Record#input.onchange} | Record#input.data_fields
     ],
     wf_tags:emit_tag(<<"input">>, nitro:render(Record#input.body), List).