mirror of
https://git.yoctoproject.org/poky
synced 2026-03-25 01:02:22 +01:00
The form for naming new custom images shows you an error message when the name already exists or you include an invalid character in it. But when an error appears, the input field was missing the red highlight. This patch applies the right class to the form controls whenever an error message is shown. (Bitbake rev: df342e7662179410467c47cd870180ea75f863d4) Signed-off-by: Belen Barros Pena <belen.barros.pena@intel.com> Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
"use strict";
|
|
|
|
/* Used for the newcustomimage_modal actions */
|
|
function newCustomImageModalInit(){
|
|
|
|
var newCustomImgBtn = $("#create-new-custom-image-btn");
|
|
var imgCustomModal = $("#new-custom-image-modal");
|
|
var invalidNameHelp = $("#invalid-name-help");
|
|
var nameInput = imgCustomModal.find('input');
|
|
|
|
var invalidMsg = "Image names cannot contain spaces or capital letters. The only allowed special character is dash (-).";
|
|
|
|
newCustomImgBtn.click(function(e){
|
|
e.preventDefault();
|
|
|
|
var baseRecipeId = imgCustomModal.data('recipe');
|
|
|
|
if (nameInput.val().length > 0) {
|
|
libtoaster.createCustomRecipe(nameInput.val(), baseRecipeId,
|
|
function(ret) {
|
|
if (ret.error !== "ok") {
|
|
console.warn(ret.error);
|
|
if (ret.error === "invalid-name") {
|
|
showError(invalidMsg);
|
|
} else if (ret.error === "already-exists") {
|
|
showError("An image with this name already exists. Image names must be unique.");
|
|
}
|
|
} else {
|
|
imgCustomModal.modal('hide');
|
|
window.location.replace(ret.url + '?notify=new');
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
function showError(text){
|
|
invalidNameHelp.text(text);
|
|
invalidNameHelp.show();
|
|
nameInput.parent().addClass('error');
|
|
}
|
|
|
|
nameInput.on('keyup', function(){
|
|
if (nameInput.val().length === 0){
|
|
newCustomImgBtn.prop("disabled", true);
|
|
return
|
|
}
|
|
|
|
if (nameInput.val().search(/[^a-z|0-9|-]/) != -1){
|
|
showError(invalidMsg);
|
|
newCustomImgBtn.prop("disabled", true);
|
|
nameInput.parent().addClass('error');
|
|
} else {
|
|
invalidNameHelp.hide();
|
|
newCustomImgBtn.prop("disabled", false);
|
|
nameInput.parent().removeClass('error');
|
|
}
|
|
});
|
|
}
|