我試圖禁用和啓用按鈕: 例如:如果我點擊修改按鈕,我想禁用它並啓用保存按鈕,如果我點擊保存按鈕,我想啓用修改按鈕並禁用保存按鈕。謝謝。Angularjs工具欄命令 - 禁用和禁用按鈕
下面的Angularjs代碼:
angular.module('virtoCommerce.catalogModule')
.controller('virtoCommerce.catalogModule.categoriesItemsListController', ['$scope', function ($scope) {
var isFieldEnabled = true;
blade.updatePermission = 'catalog:update';
... (more codes but not included)
var formScope;
$scope.setForm = function (form) { formScope = form; }
//Save the prices entered by the user.
function savePrice()
{
//TODO: Save the price information.
}
function isDirty() {
return blade.hasUpdatePermission();
};
//function enablePriceField
function enablePriceField() {
var inputList = document.getElementsByTagName("input");
var inputList2 = Array.prototype.slice.call(inputList);
if (isFieldEnabled == true) {
for (i = 0; i < inputList.length; i++) {
var row = inputList2[i];
if (row.id == "priceField") {
row.disabled = false;
}
}
} else {
for (i = 0; i < inputList.length; i++) {
var row = inputList2[i];
if (row.id == "priceField") {
row.disabled = true;
}
}
}
//Set the flag to true or false
if (isFieldEnabled == true) {
isFieldEnabled = false
} else {
isFieldEnabled = true;
}
}
var formScope;
$scope.setForm = function (form) { formScope = form; }
function canSave() {
return isDirty() && formScope && formScope.$valid;
}
//Angular toolbar commands
blade.toolbarCommands = [
{
name: "platform.commands.modify",
icon: 'fa fa-pencil',
executeMethod: function() { enablePriceField();},
canExecuteMethod: function() { return true; }
},
{
name: "platform.commands.save",
icon: 'fa fa-floppy-o',
executeMethod: function() { savePrice(); },
canExecuteMethod: canSave,
permission: blade.updatePermission
}];
}]);
比你的迴應...但我的情況我們動態地創建與Angularjs的按鈕,而不是使用HTML。如果你熟悉'virtoCommerce',按鈕是在刀片上創建的。 – eddy0223