Skip to content

Commit

Permalink
New feature #14224: Add pattern for some question type (numeric)
Browse files Browse the repository at this point in the history
Dev: starting point : some other answer need it (array text/number, short text number)
Dev: this disable submitting form directly
  • Loading branch information
Shnoulle committed Nov 7, 2018
1 parent 5aae5f2 commit b3ef5f5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Expand Up @@ -58,6 +58,7 @@
'size' : (inputsize ? inputsize : null),
'maxlength' : (maxlength ? maxlength : null),
'data-number' : 1,
'pattern' : "[-]?([0-9]+([,\.][0-9]+))?"
}))
}}
{% endif %}
Expand Down
Expand Up @@ -28,7 +28,7 @@
'sLabelWidth' : sLabelWidth,
'sInputContainerWidth' : sInputContainerWidth,
'prefix' : prefix,
'suffix' : suffix,
'suffix' : suffix
})}}
{% endblock %}
</ul>
Expand Up @@ -18,13 +18,19 @@
*/ #}

<!-- answer_row -->
{# rows is done in qanda : can set a var answer.twig to use it … #}
{% set pattern = "[-]?([0-9]+([,\.][0-9]+))?" %}
{% set title = gT('Only numbers may be entered in this field.') %}
{% if integeronly %}
{% set pattern = "[-]?([0-9]+)" %}
{% set title = gT('Only an integer value may be entered in this field.') %}
{% endif %}

<li id='javatbd{{ myfname }}' class="question-item answer-item numeric-item text-item form-group{{ extraclass }}{% if alert %} ls-error-mandatory has-error {% endif %}" {{ sDisplayStyle }}>
<!-- color code missing mandatory questions red -->
<label class="control-label col-xs-12 col-sm-{{ sLabelWidth }}{% if sLabelWidth == 0 %} hidden{% endif %}" for="answer{{myfname}}">
{{ processString(labelText) }}
</label>

<div class="col-xs-12 col-sm-{{ sInputContainerWidth }}">
{% if prefix or suffix %}
<div class="ls-input-group">
Expand All @@ -42,6 +48,8 @@
'maxlength': (maxlength ? maxlength : null),
'data-number' : 1,
'data-integer' : integeronly,
'pattern' : pattern,
'title' : title
})
}}
{% if suffix %}
Expand Down
12 changes: 9 additions & 3 deletions application/views/survey/questions/answer/numerical/answer.twig
Expand Up @@ -30,18 +30,24 @@
{% if prefix != '' %}
<div class='ls-input-group-extra prefix-text prefix'>{{ processString(prefix) }}</div>
{% endif %}

{% set pattern = "[-]?([0-9]+([,\.][0-9]+))?" %}
{% set title = gT('Only numbers may be entered in this field.') %}
{% if integeronly %}
{% set pattern = "[-]?([0-9]+)" %}
{% set title = gT('Only an integer value may be entered in this field.') %}
{% endif %}
{# Want to use HTML5 number type? Think again: Doesn't work as we want with locale: http://stackoverflow.com/questions/13412204/localization-of-input-type-number #}
{# type=number is localized by default : broke API, (disable survey settings, but surely better) #}
{{ C.Html.textField(id,fValue,({
'id' : "answer"~id,
'class' : "form-control "~answertypeclass,
'title' : gT('Only numbers may be entered in this field.'),
'title' : title,
'size' : (inputsize ? inputsize : null),
'maxlength' : (maxlength ? maxlength : null),
'data-number' : 1,
'data-integer' : integeronly,
'aria-labelledby' : "ls-question-text-"~basename
'aria-labelledby' : "ls-question-text-"~basename,
'pattern' : pattern
}))
}}
<!-- Suffix -->
Expand Down

0 comments on commit b3ef5f5

Please sign in to comment.