unique shortcode valiate

This commit is contained in:
trung nguyen thanh 2017-03-08 10:50:30 +07:00
parent b02bb32be5
commit 7c29e49db9
1 changed files with 33 additions and 8 deletions

View File

@ -1,4 +1,4 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<!--[if lt IE 10]> <!--[if lt IE 10]>
@ -1019,35 +1019,34 @@
<div class="form-group"> <div class="form-group">
<label class="col-2">Page Up</label> <label class="col-2">Page Up</label>
<div class="col-8 "> <div class="col-8 ">
<span class="keyboard">Shift + </span><input type="text" class="form-control input-sm" id="pageUp" maxlength="1"> <span class="keyboard">Shift + </span><input type="text" class="form-control input-sm js-shortkey" id="pageUp" maxlength="1">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-2">Page Down</label> <label class="col-2">Page Down</label>
<div class="col-8 "> <div class="col-8 ">
<span class="keyboard">Shift + </span><input type="text" class="form-control input-sm" id="pageDown" maxlength="1"> <span class="keyboard">Shift + </span><input type="text" class="form-control input-sm js-shortkey" id="pageDown" maxlength="1">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-2">Shuffle</label> <label class="col-2">Shuffle</label>
<div class="col-8 "> <div class="col-8 ">
<span class="keyboard">Shift + </span><input type="text" class="form-control input-sm" id="shuffle" maxlength="1"> <span class="keyboard">Shift + </span><input type="text" class="form-control input-sm js-shortkey" id="shuffle" maxlength="1">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-2">Unshuffle</label> <label class="col-2">Unshuffle</label>
<div class="col-8 "> <div class="col-8 ">
<span class="keyboard">Shift + </span><input type="text" class="form-control input-sm" id="unShuffle" maxlength="1"> <span class="keyboard">Shift + </span><input type="text" class="form-control input-sm js-shortkey" id="unShuffle" maxlength="1">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-2">Duochrome</label> <label class="col-2">Duochrome</label>
<div class="col-8 "> <div class="col-8 ">
<span class="keyboard">Shift + </span><input type="text" class="form-control input-sm" id="duoBG" maxlength="1"> <span class="keyboard">Shift + </span><input type="text" class="form-control input-sm js-shortkey" id="duoBG" maxlength="1">
</div> </div>
</div> </div>
</fieldset> </fieldset>
<fieldset class="footer-fieldset"> <fieldset class="footer-fieldset">
<div class="action-button"> <div class="action-button">
@ -1971,7 +1970,30 @@
} }
return result; return result;
}; };
this.ValidateDuplicateKey = function (element) {
$('.errorShortKey').remove();
var arr = $('.js-shortkey').map(function () {
return this.value; // $(this).val()
}).get();
function countInArray(array, what) {
return array.filter(item => item == what).length;
}
var result = false;
var currentVal = $(element).val();
if (currentVal.trim() != "") {
if (countInArray(arr, currentVal) > 1) {
result = true;
}
}
if (result) {
$(element).parent().append('<span class="errorMsg errorShortKey">ShortKey ' + currentVal + ' is duplicate. Please try again.</span>');
$(element).val("");
}
else {
$(element).parent().find('.errorShortKey').remove();
}
return result;
};
this.SetLocalStorage = function () { this.SetLocalStorage = function () {
localStorage.setItem("Optotype", localOptotype); localStorage.setItem("Optotype", localOptotype);
localStorage.setItem("Alphabet", alphabetType); localStorage.setItem("Alphabet", alphabetType);
@ -2509,6 +2531,9 @@
$('#updateSetting').removeClass('disabled-btn'); $('#updateSetting').removeClass('disabled-btn');
} }
}); });
$('.js-shortkey').on('blur', function () {
validateElement.ValidateDuplicateKey(this);
});
this.SelectOptotype(); this.SelectOptotype();
this.ColorPicker(); this.ColorPicker();
this.UpdateSetting(); this.UpdateSetting();