-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
135 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,137 @@ | ||
angular.module('myApp', ['validation']) | ||
|
||
// ------------------- | ||
// config phase | ||
// ------------------- | ||
.config(['$validationProvider', function ($validationProvider) { | ||
|
||
var defaultMsg, | ||
expression; | ||
|
||
/** | ||
* Setup a default message for Url | ||
*/ | ||
defaultMsg = { | ||
url: { | ||
error: 'This is a error url given by user', | ||
success: 'It\'s Url' | ||
} | ||
}; | ||
|
||
$validationProvider.setDefaultMsg(defaultMsg); | ||
|
||
|
||
/** | ||
* Setup a new Expression and default message | ||
* In this example, we setup a IP address Expression and default Message | ||
*/ | ||
expression = { | ||
ip: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ | ||
}; | ||
|
||
defaultMsg = { | ||
ip: { | ||
error: 'This isn\'t ip address', | ||
success: 'It\'s ip' | ||
} | ||
}; | ||
|
||
$validationProvider.setExpression(expression); | ||
$validationProvider.setDefaultMsg(defaultMsg); | ||
|
||
// or we can just setup directly | ||
$validationProvider.setDefaultMsg({ ip: { error: 'This no ip', success: 'this ip'}}); | ||
$validationProvider.setExpression({ ip: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ }); | ||
|
||
/** | ||
* Additions validation | ||
*/ | ||
$validationProvider.setExpression({ | ||
(function () { | ||
angular.module('myApp', ['validation']) | ||
|
||
// ------------------- | ||
// config phase | ||
// ------------------- | ||
.config(['$validationProvider', function ($validationProvider) { | ||
|
||
var defaultMsg, | ||
expression; | ||
|
||
/** | ||
* Setup a default message for Url | ||
*/ | ||
defaultMsg = { | ||
url: { | ||
error: 'This is a error url given by user', | ||
success: 'It\'s Url' | ||
} | ||
}; | ||
|
||
$validationProvider.setDefaultMsg(defaultMsg); | ||
|
||
|
||
/** | ||
* Setup a new Expression and default message | ||
* In this example, we setup a IP address Expression and default Message | ||
*/ | ||
expression = { | ||
ip: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ | ||
}; | ||
|
||
defaultMsg = { | ||
ip: { | ||
error: 'This isn\'t ip address', | ||
success: 'It\'s ip' | ||
} | ||
}; | ||
|
||
$validationProvider.setExpression(expression); | ||
$validationProvider.setDefaultMsg(defaultMsg); | ||
|
||
// or we can just setup directly | ||
$validationProvider.setDefaultMsg({ ip: { error: 'This no ip', success: 'this ip'}}); | ||
$validationProvider.setExpression({ ip: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ }); | ||
|
||
/** | ||
* @param value , user input | ||
* @returns {boolean} true iff valid | ||
* Additions validation | ||
*/ | ||
huei: function (value) { | ||
return value === 'Huei Tan'; | ||
} | ||
}); | ||
|
||
$validationProvider.setDefaultMsg({ | ||
huei: { | ||
error: 'This should be Huei Tan', | ||
success: 'Thanks!' | ||
} | ||
}); | ||
}]) | ||
|
||
// ------------------- | ||
// controller phase | ||
// ------------------- | ||
|
||
.controller('index', ['$scope', '$injector', function ($scope, $injector) { | ||
|
||
// Injector | ||
var $validationProvider = $injector.get('$validation'); | ||
|
||
|
||
// Initial Value | ||
$scope.form = { | ||
requiredCallback: 'required', | ||
checkValid: $validationProvider.checkValid, | ||
submit: function (form) { | ||
$validationProvider.validate(form); | ||
}, | ||
reset: function (form) { | ||
$validationProvider.reset(form); | ||
} | ||
}; | ||
|
||
$scope.form2 = { | ||
checkValid: $validationProvider.checkValid, | ||
submit: function (form) { | ||
$validationProvider.validate(form); | ||
}, | ||
reset: function (form) { | ||
$validationProvider.reset(form); | ||
} | ||
}; | ||
|
||
$scope.form3 = { | ||
checkValid: $validationProvider.checkValid, | ||
submit: function (form) { | ||
$validationProvider.validate(form) | ||
.success($scope.success) | ||
.error($scope.error); | ||
}, | ||
reset: function (form) { | ||
$validationProvider.reset(form); | ||
} | ||
}; | ||
|
||
$scope.form4 = { | ||
changeErrorMsg: 'This is the First Error Msg', | ||
changeMsg: function () { | ||
$scope.form4.changeErrorMsg = 'This is the Second Error Msg'; | ||
} | ||
}; | ||
|
||
$scope.form5 = { | ||
checkValid: $validationProvider.checkValid, | ||
submit: function (form) { | ||
$validationProvider.validate(form); | ||
}, | ||
reset: function (form) { | ||
$validationProvider.reset(form); | ||
} | ||
}; | ||
|
||
// Callback method | ||
$scope.success = function (message) { | ||
alert('Success ' + message); | ||
}; | ||
|
||
$scope.error = function (message) { | ||
alert('Error ' + message); | ||
}; | ||
}]); | ||
$validationProvider.setExpression({ | ||
/** | ||
* @param value , user input | ||
* @returns {boolean} true iff valid | ||
*/ | ||
huei: function (value) { | ||
return value === 'Huei Tan'; | ||
} | ||
}); | ||
|
||
$validationProvider.setDefaultMsg({ | ||
huei: { | ||
error: 'This should be Huei Tan', | ||
success: 'Thanks!' | ||
} | ||
}); | ||
}]) | ||
|
||
// ------------------- | ||
// controller phase | ||
// ------------------- | ||
.controller('index', ['$scope', '$injector', function ($scope, $injector) { | ||
|
||
// Injector | ||
var $validationProvider = $injector.get('$validation'); | ||
|
||
|
||
// Initial Value | ||
$scope.form = { | ||
requiredCallback: 'required', | ||
checkValid: $validationProvider.checkValid, | ||
submit: function (form) { | ||
$validationProvider.validate(form); | ||
}, | ||
reset: function (form) { | ||
$validationProvider.reset(form); | ||
} | ||
}; | ||
|
||
$scope.form2 = { | ||
checkValid: $validationProvider.checkValid, | ||
submit: function (form) { | ||
$validationProvider.validate(form); | ||
}, | ||
reset: function (form) { | ||
$validationProvider.reset(form); | ||
} | ||
}; | ||
|
||
$scope.form3 = { | ||
checkValid: $validationProvider.checkValid, | ||
submit: function (form) { | ||
$validationProvider.validate(form) | ||
.success($scope.success) | ||
.error($scope.error); | ||
}, | ||
reset: function (form) { | ||
$validationProvider.reset(form); | ||
} | ||
}; | ||
|
||
$scope.form4 = { | ||
changeErrorMsg: 'This is the First Error Msg', | ||
changeMsg: function () { | ||
$scope.form4.changeErrorMsg = 'This is the Second Error Msg'; | ||
} | ||
}; | ||
|
||
$scope.form5 = { | ||
checkValid: $validationProvider.checkValid, | ||
submit: function (form) { | ||
$validationProvider.validate(form); | ||
}, | ||
reset: function (form) { | ||
$validationProvider.reset(form); | ||
} | ||
}; | ||
|
||
// Callback method | ||
$scope.success = function (message) { | ||
alert('Success ' + message); | ||
}; | ||
|
||
$scope.error = function (message) { | ||
alert('Error ' + message); | ||
}; | ||
}]); | ||
}).call(this); |