Skip to content

Conversation

@zvaraondrej
Copy link

Allows user to specify, weather to use $viewValue or $modelValue for evaluation when form is submitted.

By default uses $viewValue; by adding use-view-value="false" forces to use $modelValue;

This need raises from a need of localized number inputs, which have to be stored in a $viewValue as a string (e.g. "2 000,0"), however in a $modelValue they are stored as a properly formatted number (2000). This can be done by using a custom directive with properly specified $formatters and $parsers.

src/rule.js Outdated
email: /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/,
number: /^\d+$/,
minlength: function(value, scope, element, attrs, param) {
value += '';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this stringify?

Copy link
Author

@zvaraondrej zvaraondrej Jan 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is as follows: if we use $modelValue whose value data type is Number, then value.length results in undefined;

The question is, if the validator "maxlength" or "minlength" should be used with the Number data type; instead, maybe something like "maxVal" and "minVal" could be created on the app side.

In that case, It would be probably desired to remove usage of the maxlength from tests.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this is valid.

But I would like to remove this commit out of this pr scope (using model value)

then we can have another pr/commit for separate maxlength and maxvalue but it doesn't really matter, it's just a rule and everyone can customise it. 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, perfect. So Ill remove the string conversion, update the related tests and squash the commits to single one. Regarding the validation expression, your correct - it doesn't really matter now.

The last thing: "can you remove those unwanted indent/format commit?" could you please specify
more in detail which lines should be changed? (If not already discussed above) Thanks :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, perfect. So Ill remove the string conversion, update the related tests and squash the commits to single one. Regarding the validation expression, your correct - it doesn't really matter now.

Perfect 🍻

more in detail which lines should be changed? (If not already discussed above) Thanks :)

Sure.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Ill remove the string conversion, update the related tests and squash the commits to single one.

Done

more in detail which lines should be changed? (If not already discussed above) Thanks :)
Sure.

If there's anything else left to be done, let me know please :) Thanks.

@hueitan
Copy link
Owner

hueitan commented Jan 19, 2017

yes, this is a real need case. can you remove those unwanted indent/format commit?

Copy link
Owner

@hueitan hueitan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it is not done yet. if you didn't update anything on demo.js, please kindly revert the change of demo.js, otherwise I can't merge this commit.

demo/demo.js Outdated
// -------------------
.config(['$validationProvider', function($validationProvider) {
var defaultMsg;
var expression;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwanted indentation commit.

demo/demo.js Outdated
error: 'This is a error url given by user',
success: 'It\'s Url'
}
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

demo/demo.js Outdated
error: 'This no ip',
success: 'this ip'
error: 'This isn\'t ip address',
success: 'It\'s ip'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try not to update the text, because it is out of scope.

alert('Error ' + message);
};
}]);
}).call(this);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, we don't update anything on this file demo.js, unless you add an example for useViewValue in demo page.

@zvaraondrej
Copy link
Author

Okay, now I see where was the unwanted indentation. It came by mistake, sorry. It should be fixed now.

Copy link
Owner

@hueitan hueitan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect now!

@hueitan
Copy link
Owner

hueitan commented Jan 20, 2017

There are still some conflicts over the file, do you mind pull the latest from master, and run the grunt build again?

@coveralls
Copy link

coveralls commented Jan 20, 2017

Coverage Status

Coverage increased (+0.02%) to 93.976% when pulling c538ea9 on zvaraondrej:using-model-value into aa13b20 on huei90:master.

@zvaraondrej
Copy link
Author

Seems like it should be fine now. What do you think? :)

@hueitan
Copy link
Owner

hueitan commented Jan 20, 2017

yep, done! 🍻

@hueitan hueitan merged commit 73a8fae into hueitan:master Jan 20, 2017
@hueitan
Copy link
Owner

hueitan commented Jan 20, 2017

There is one more thing we can improve, try to add the explanation in Q&A section.

with the explanation you given above

Allows user to specify, weather to use $viewValue or $modelValue for evaluation when form is submitted.
By default uses $viewValue; by adding use-view-value="false" forces to use $modelValue;
This need raises from a need of localized number inputs, which have to be stored in a $viewValue as a string (e.g. "2 000,0"), however in a $modelValue they are stored as a properly formatted number (2000). This can be done by using a custom directive with properly specified $formatters and $parsers.

@zvaraondrej
Copy link
Author

It seems like I had to create a new PR for this one, so there's another opened...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants