-
Notifications
You must be signed in to change notification settings - Fork 6
enable passive and array validator #3
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
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
df1a627
add the repository property in package.json
lyweiwei 798ff25
change 4739243: Fix the bug that we couldn't copy and paste a string …
ljqx 89fef23
change 4777824: For ko observables which extend ko string length vali…
ljqx 84d61e6
change 4745636: passive validator
ljqx b109cc4
change 4830653: array validator
ljqx cfc5c03
change 4744854: Fix the bug that ko number validation doesn't support…
ljqx 6bc2759
change 4776647: Update number-validator to return valid status for
ljqx a619da4
fix $/i18n problem
ljqx 0fa950a
fix component/humanize/decimal
ljqx d7b21ae
fix test
ljqx b71ba63
test for passive validator
ljqx 4af9780
add test for array validator
ljqx ccc9c9b
test for entrance
ljqx 5d7757a
comment out unused code in humanize/decimal
ljqx 00d0fa2
add tests for new code
ljqx 774e488
force rerun
ljqx d9d3786
Merge pull request #2 from ljqx/merge-with-SD
lyweiwei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,156 @@ | ||
define(['component/ko-validation/config'], function (config) { | ||
'use strict'; | ||
|
||
function getParts(input, decimalChar) { | ||
input = '' + input; | ||
var fracIndex = input.lastIndexOf(decimalChar) + 1; | ||
var parts = { | ||
negative: input.substring(0, 1) == '-' ? '-' : '', | ||
fractional: fracIndex ? input.substr(fracIndex).replace(/\D/g, '') : '', | ||
integral: (fracIndex ? input.substring(0, fracIndex) : input).replace(/\D/g, '') | ||
}; | ||
parts.toFloat = function toFloat() { | ||
return parseFloat(parts.negative + '0' + parts.integral + '.' + parts.fractional); | ||
}; | ||
return parts; | ||
} | ||
|
||
function getFormat() { | ||
return { | ||
decimalChar : config.decimalPoint, | ||
groupChar : config.groupPoint, | ||
groupSize : config.groupSize, | ||
percentSymbol : config.percentSymbol, | ||
percentGroupSize : config.percentGroupSize, | ||
percentGroupSeparator : config.percentGroupSeparator, | ||
percentPositivePattern : config.percentPositivePattern, | ||
numberOfDigits : config.numberOfDigits, | ||
percentDecimalDigits : config.percentDecimalDigits, | ||
percentDecimalSeparator : config.percentDecimalSeparator, | ||
}; | ||
} | ||
|
||
var dn = { | ||
// true/false if exactly formatted correct, no smoothing | ||
isValid: function isValid (localizedInput, allowNoIntegralPart) { | ||
var format = getFormat() | ||
, minGroupSize = 0 // allowNoIntegralPart ? 0 : 1 | ||
, re = new RegExp('^[+-]?[0-9]{' + minGroupSize + ',' + format.groupSize + '}(?:\\' + format.groupChar + '?[0-9]{' + format.groupSize + '})*(?:\\' + format.decimalChar + '[[0-9]*)?$') | ||
, isValid = re.test(localizedInput); | ||
|
||
return isValid; | ||
}, | ||
|
||
// returns null if invalid | ||
// rounds if number of digits is passed, otherwise no rounding | ||
fromLocalToFloat: function fromLocalToFloat(localizedInput /*, numberOfDigits */) { | ||
var format = getFormat(), | ||
parts = getParts(localizedInput, format.decimalChar); | ||
// if (parts.fractional || parts.integral) { | ||
var floatValue = parts.toFloat(); | ||
// if (numberOfDigits) { | ||
// floatValue = parseFloat(floatValue.toFixed(numberOfDigits)); | ||
// } | ||
return floatValue; | ||
// } | ||
// return null; | ||
}, | ||
|
||
// // returns null if isValid == false | ||
// fromLocalToStringStrict: function (localizedInput, numberOfDigits) { | ||
// if (!dn.isValid(localizedInput)) | ||
// { | ||
// return null; | ||
// } | ||
|
||
// return dn.fromLocalToString(localizedInput, numberOfDigits); | ||
// }, | ||
|
||
// // used to validate & format user input | ||
// fromLocalToString: function fromLocalToString(localizedInput, numberOfDigits) { | ||
// var format = getFormat(), | ||
// parts = getParts(localizedInput, format.decimalChar), | ||
// numberOfDigits = typeof numberOfDigits === 'undefined' ? format.numberOfDigits : numberOfDigits, | ||
// cleanedAndRounded = parts.toFloat().toFixed(numberOfDigits).split('.'), | ||
// formattedIntegral = '', | ||
// i = cleanedAndRounded[0].length; | ||
|
||
// for (; i > format.groupSize; i -= format.groupSize) { | ||
// formattedIntegral = format.groupChar + cleanedAndRounded[0].substring(i - format.groupSize, i) + formattedIntegral; | ||
// } | ||
|
||
// formattedIntegral = cleanedAndRounded[0].substring(0, i) + formattedIntegral; | ||
// if (numberOfDigits) { | ||
// formattedIntegral += format.decimalChar + cleanedAndRounded[1]; | ||
// } | ||
|
||
// return formattedIntegral; | ||
// }, | ||
|
||
// // format input to string in percentage format | ||
// fromLocalToPercentString: function fromLocalToString(localizedInput, numberOfDigits) { | ||
// var input = localizedInput * 100; | ||
// var format = getFormat(), | ||
// parts = getParts(input, format.percentDecimalSeparator), | ||
// numberOfDigits = typeof numberOfDigits === 'undefined' ? format.percentDecimalDigits : numberOfDigits, | ||
// cleanedAndRounded = parts.toFloat().toFixed(numberOfDigits).split('.'), | ||
// formattedIntegral = '', | ||
// i = cleanedAndRounded[0].length; | ||
|
||
// for (; i > format.percentGroupSize; i -= format.percentGroupSize) { | ||
// formattedIntegral = format.percentGroupSeparator + cleanedAndRounded[0].substring(i - format.percentGroupSize, i) + formattedIntegral; | ||
// } | ||
|
||
// formattedIntegral = cleanedAndRounded[0].substring(0, i) + formattedIntegral; | ||
// if (numberOfDigits) { | ||
// formattedIntegral += format.percentDecimalSeparator + cleanedAndRounded[1]; | ||
// } | ||
|
||
// switch (format.percentPositivePattern) { | ||
// //Associated pattern: n % | ||
// case '0': | ||
// formattedIntegral = formattedIntegral + ' ' + format.percentSymbol; | ||
// break; | ||
// //Associated pattern: n% | ||
// case '1': | ||
// formattedIntegral = formattedIntegral + format.percentSymbol; | ||
// break; | ||
// //Associated pattern: %n | ||
// case '2': | ||
// formattedIntegral = format.percentSymbol + formattedIntegral; | ||
// break; | ||
// //Associated pattern: % n | ||
// case '3': | ||
// formattedIntegral = format.percentSymbol + ' ' + formattedIntegral; | ||
// break; | ||
// } | ||
|
||
// return formattedIntegral; | ||
// } | ||
}; | ||
|
||
// // used to format float values from MT/DB (e.g., always a real number XXX.YY with a period for decimal place | ||
// dn.fromFloatToString = function fromFloatToString(floatInput, numberOfDigits) { | ||
// var format = getFormat(); | ||
// return dn.fromLocalToString(floatInput.toString().replace('.', format.decimalChar), numberOfDigits); | ||
// }; | ||
|
||
// // Used in Location Targeting control to convert Lat/Lon to string using customer culture information | ||
// dn.fromCoordinateToString = function fromCoordinateToString(value) { | ||
// if (value && (typeof decimalFormatter !== 'undefined')) { | ||
// value = value.toString().replace(".", decimalFormatter.decimalChar); | ||
// } | ||
|
||
// return value; | ||
// }; | ||
|
||
// // used to format float value to string with a percent sign. Does NOT convert the float to a percent. Ex: 42.07 => 42.07%, 0.15 => 0.15% | ||
// dn.fromFloatToPercentString = function fromFloatToPercentString(floatInput, numberOfDigits) { | ||
// var format = getFormat(); | ||
// //fromLocalToPercentString will multiply the number by 100 and displayed with a percent symbol. | ||
// var input = floatInput / 100; | ||
// return dn.fromLocalToPercentString(input.toString().replace('.', format.decimalChar), numberOfDigits); | ||
// }; | ||
|
||
return dn; | ||
}); |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_.pick?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljqx I sign off, and will merge the change, please take care of the node in next iteration.
Thanks
Wei