Fixes decimal inputs
This commit is contained in:
parent
7462a49066
commit
93028b9be0
3 changed files with 17 additions and 11 deletions
|
|
@ -53,8 +53,8 @@
|
|||
<span translate>Amount</span>
|
||||
</label>
|
||||
<div class="input">
|
||||
<input type="number" id="amount" name="amount" ng-attr-placeholder="{{'Amount'|translate}}"
|
||||
ng-model="_customAmount" valid-amount required autocomplete="off">
|
||||
<input type="text" id="amount" name="amount" ng-attr-placeholder="{{'Amount'|translate}}"
|
||||
ng-model="_customAmount" valid-amount required autocomplete="off" pattern="[0-9]+([\.,][0-9]+)*">
|
||||
<input type="number" id="alternative" name="alternative" ng-model="_customAlternative" style="display:none">
|
||||
<a class="postfix" ng-click="toggleAlternative()">{{unitName}}</a>
|
||||
</div>
|
||||
|
|
@ -63,8 +63,8 @@
|
|||
<label for="alternative"><span translate>Amount in</span> {{ alternativeName }}
|
||||
</label>
|
||||
<div class="input">
|
||||
<input type="number" id="alternative" name="alternative" ng-attr-placeholder="{{'Amount'|translate}}"
|
||||
ng-model="_customAlternative" requiredautocomplete="off" required>
|
||||
<input type="text" id="alternative" name="alternative" ng-attr-placeholder="{{'Amount'|translate}}"
|
||||
ng-model="_customAlternative" requiredautocomplete="off" pattern="[0-9]+([\.,][0-9]+)*" required>
|
||||
<input type="number" id="amount" name="amount" ng-model="_customAmount" style="display:none">
|
||||
<a class="postfix" ng-click="toggleAlternative()"> {{ alternativeIsoCode }}</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -382,8 +382,11 @@
|
|||
<span translate>Amount</span>
|
||||
</label>
|
||||
<div class="input">
|
||||
<input type="number" id="amount" ng-disabled="home.blockUx || home.lockAmount" name="amount" ng-attr-placeholder="{{'Amount'|translate}}" ng-minlength="0.00000001" ng-maxlength="10000000000" ng-model="_amount" valid-amount required autocomplete="off" ng-focus="home.formFocus('amount')" ng-blur="home.formFocus(false)">
|
||||
<input type="number" id="alternative" name="alternative" ng-model="_alternative" style="display:none">
|
||||
<input type="text" id="amount" ng-disabled="home.blockUx || home.lockAmount" name="amount"
|
||||
ng-attr-placeholder="{{'Amount'|translate}}"
|
||||
ng-model="_amount" valid-amount required autocomplete="off" ng-focus="home.formFocus('amount')"
|
||||
ng-blur="home.formFocus(false)" pattern="[0-9]+([\.,][0-9]+)*">
|
||||
<input type="text" id="alternative" name="alternative" ng-model="_alternative" style="display:none">
|
||||
<a class="postfix" ng-click="home.showAlternative()">{{home.unitName}}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -391,8 +394,11 @@
|
|||
<label for="alternative"><span translate>Amount in</span> {{ home.alternativeName }}
|
||||
</label>
|
||||
<div class="input">
|
||||
<input type="number" id="alternative" ng-disabled="home.blockUx || !home.isRateAvailable || home.lockAmount" name="alternative" ng-attr-placeholder="{{'Amount'|translate}}" ng-model="_alternative" requiredautocomplete="off" ng-focus="home.formFocus('amount')" ng-blur="home.formFocus(false)">
|
||||
<input type="number" id="amount" name="amount" ng-model="_amount" style="display:none">
|
||||
<input type="text" id="alternative" ng-disabled="home.blockUx || !home.isRateAvailable ||
|
||||
home.lockAmount" name="alternative" ng-attr-placeholder="{{'Amount'|translate}}"
|
||||
ng-model="_alternative" required autocomplete="off" ng-focus="home.formFocus('amount')"
|
||||
ng-blur="home.formFocus(false)" pattern="[0-9]+([\.,][0-9]+)*">
|
||||
<input type="text" id="amount" name="amount" ng-model="_amount" style="display:none">
|
||||
<a class="postfix" ng-click="home.hideAlternative()"> {{ home.alternativeIsoCode }}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -87,22 +87,22 @@ angular.module('copayApp.directives')
|
|||
])
|
||||
.directive('validAmount', ['configService', '$locale',
|
||||
function(configService, locale) {
|
||||
var formats = locale.NUMBER_FORMATS;
|
||||
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function(scope, element, attrs, ctrl) {
|
||||
var val = function(value) {
|
||||
if (value) value = value.replace(/,/g, '.');
|
||||
var settings = configService.getSync().wallet.settings;
|
||||
var vNum = Number((value * settings.unitToSatoshi).toFixed(0));
|
||||
|
||||
if (typeof value == 'undefined') {
|
||||
if (typeof value == 'undefined' || value == 0) {
|
||||
ctrl.$pristine = true;
|
||||
}
|
||||
|
||||
if (typeof vNum == "number" && vNum > 0) {
|
||||
var decimals = Number(settings.unitDecimals);
|
||||
var sep_index = ('' + value).indexOf(formats.DECIMAL_SEP);
|
||||
var sep_index = ('' + value).indexOf('.');
|
||||
var str_value = ('' + value).substring(sep_index + 1);
|
||||
if (sep_index > 0 && str_value.length > decimals) {
|
||||
ctrl.$setValidity('validAmount', false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue