使用ember应用程序。我有这个表格,其中包含姓名,cc号码,到期日和安全号码。我可以在名称上退格,但是我不能删除任何其他内容,这只发生在Firefox中。
<div class="form-group cc-name input-row {{if nameValid 'has-success'}}">
<label class="label label--sm">Name on Card</label>
{{input type="text" value=name class="form-control"}}
</div>
<div class="form-group cc-number input-row {{if numberValid 'has-success'}}">
<label for="cc-number" class="label label--sm">Credit Card Number</label>
{{input-credit-card-number number=number class="form-control"}}
<div class="card-type {{if type 'show' 'hide'}}">
{{#if type}}
{{inline-svg type class="icon icon--credit-card"}}
{{/if}}
</div>
</div>
<div class="input-row input-row--inline">
<div class="form-group cc-expiration input-col--50 {{if expirationValid 'has-success'}}">
<label class="control-label label--sm">Expiration</label>
{{input-credit-card-expiration month=month year=year class="form-control"}}
</div>
<div class="form-group cc-cvc input-col--50 {{if cvcValid 'has-success'}}">
<label class="control-label label--sm">Security Code</label>
{{input-credit-card-cvc cvc=cvc class="form-control"}}
</div>
</div>
这是我需要覆盖的代码:
import Ember from 'ember';
import hasTextSelected from 'ember-credit-cards/utils/has-text-selected';
import formatters from 'ember-credit-cards/utils/formatters';
import cards from 'ember-credit-cards/utils/cards';
var cardFromNumber = cards.fromNumber;
var computed = Ember.computed;
function inputValid(value) {
value = (value + '').replace(/\D/g, '');
var card = cardFromNumber(value);
if (card) {
return value.length <= card.length[card.length.length - 1];
} else {
return value.length <= 16;
}
}
export default Ember.TextField.extend({
classNames: ['input-credit-card-number'],
placeholder: '•••• •••• •••• ••••',
autocomplete: 'cc-number',
type: 'tel',
keyPress: function(e) {
var digit = String.fromCharCode(e.which);
console.log(digit);
if (!/^\d+$/.test(digit)) {
return false;
}
var el = this.$();
if (hasTextSelected(el)) {
return true;
}
var value = el.val() + digit;
return inputValid(value);
console.log(value);
},
value: computed('number', function(key, value) {
var number = this.get('number');
if (arguments.length > 1) {
number = value;
this.set('number', value);
}
return formatters.formatNumber(number);
})
});
答案 0 :(得分:0)
此代码适用于我:
ValueData