-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reset method #185
Comments
@enesaltinok Thanks for raising up this question. In general,
After the reset, we should keep the orignal values, if default value is not given, make the field empty. But in the case, input with the attribute again, thanks for reporting this. |
@Nazanin1369 @lvarayut see this. seems given the default value in angularjs using native form Considering, should we use the attribute |
Even if We can handle |
I can't agree with you more. But I prefer to stick with the Because people use reset more than clear in the Form term. In this situation, using AngularJS already breaks the original Form native behaviour, so we can't or hardly to make it back to the normal case. I suggest, we should think more about, what is Or we should support - how to set the default value in angular-validation. |
I prefer reset because It has the same behavior as native form (https://www.w3.org/wiki/HTML/Elements/input/reset) I think the API would be : <input ng-model="username" o-value ="username" /> We have to catch var watchDestructor = $scope.$watch($attrs.oValue,function(newVal, oldVal){
if(typeof oldVal === 'undefined' && oldVal !== newVal)
{
//Update `defaultValue ` here
document.querySelector('input[o-value="'+$attrs.oValue+'"]').defaultValue = newVal;
watchDestructor();
}
}); Then, We just use |
@hungdoan2 This is a good idea 🍻 |
It's a good one. |
hello friends, /**
* clears the validation status for the specific form
* @param form
*/
this.clear = function(form) {
if (form === undefined) {
console.error('This is not a regular Form name scope');
return;
}
if (form.validationId) {
$scope.$broadcast(form.$name + 'clear-' + form.validationId);
} else if (form.constructor === Array) {
for (var k in form) {
$scope.$broadcast(form[k].$name + 'clear-' + form[k].validationId);
}
} else {
for (var i in form) {
if (i[0] !== '$' && form[i].hasOwnProperty('$dirty')) {
$scope.$broadcast(i + 'clear-' + form[i].validationId);
}
}
}
}; /**
* Clears the validation for specific form
*/
scope.$on(ctrl.$name + 'clear-' + uid, function() {
/**
* clear scope.$watch here
* clear the $watch method to prevent
* $watch again while clearing the form
*/
watch();
$timeout(function() {
ctrl.$setPristine();
ctrl.$setValidity(ctrl.$name, undefined);
ctrl.$render();
if ($validationProvider.clearCallback) $validationProvider.clearCallback(element);
});
}); In your controller: var $validationProvider = $injector.get('$validation');
angular.extend($validationProvider, {
// adapt to your success/error implementation
clearCallback: function(element) {
$(element).parents('.form-group:first').removeClass('has-success').removeClass('has-error');
$(element).siblings('i.form-control-feedback').remove();
}
}); And then when needed, call $validationProvider.clear(form); |
I just found a way to define o-value like document write JS:
HTML:
|
Hi,
Calling reset(form) method clears form field values.
But I need the keep values.
Is there any way keeping the values and clearing the error messages?
The text was updated successfully, but these errors were encountered: