Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

made possible to use binded data in min, max and remove required validation from min/max #666

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/widget/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,19 +570,32 @@ angularInputType('radio', function(inputElement) {

function numericRegexpInputType(regexp, error) {
return ['$element', function(inputElement) {
var widget = this,
min = 1 * (inputElement.attr('min') || Number.MIN_VALUE),
max = 1 * (inputElement.attr('max') || Number.MAX_VALUE);
var widget = this;
var modelScope = inputElement.scope();

watchElementProperty(modelScope, widget, 'min', inputElement);
watchElementProperty(modelScope, widget, 'max', inputElement);

widget.$on('$validate', function(event){
var value = widget.$viewValue,
filled = value && trim(value) != '',
valid = isString(value) && value.match(regexp);
valid = !!(isString(value) && value.match(regexp)),
isInvalid = filled && !valid;
if (widget.$error[error] != isInvalid){
widget.$emit(isInvalid ? '$invalid' : '$valid', error);
}

widget.$emit(!filled || valid ? "$valid" : "$invalid", error);
filled && (value = 1 * value);
widget.$emit(valid && value < min ? "$invalid" : "$valid", "MIN");
widget.$emit(valid && value > max ? "$invalid" : "$valid", "MAX");

var isToLow = filled && valid && widget.$min && trim(widget.$min) != '' && value < (1 * widget.$min),
isToHigh = filled && valid && widget.$max && trim(widget.$max) != '' && value > (1 * widget.$max);

if (widget.$error.MIN != isToLow){
widget.$emit(isToLow ? '$invalid' : '$valid', 'MIN');
}
if (widget.$error.MAX != isToHigh){
widget.$emit(isToHigh ? '$invalid' : '$valid', 'MAX');
}
});

widget.$parseView = function() {
Expand Down
17 changes: 15 additions & 2 deletions test/widget/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,16 +572,29 @@ describe('widget: input', function() {


itShouldVerify('integer',
[null, '', '1', '12', '-4', '+13'],
[null, undefined, '', '1', '12', '-4', '+13'],
['x', '12b', '-6', '101', '1.', '1.2'],
{min:-5, max:100});


itShouldVerify('integer',
[null, '', '0', '1'],
[null, undefined, '', '0', '1'],
['-1', '2'],
{min:0, max:1});

itShouldVerify('integer',
[],
[null, '', undefined],
{required:true});

itShouldVerify('integer',
[null, undefined, '', '0', '1'],
['-2','2'],
{min: "{{min_value}}", max:"{{max_value}}"}, function(scope){
scope.min_value = "-1";
scope.max_value = "1";
});


itShouldVerify('text with inlined pattern constraint',
['', '000-00-0000', '123-45-6789'],
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy