PHP Checkboxes won't undo disable attribute, but will uncheck - checkbox

I have a few pages of long code, but I'm having difficulty getting this to work. The following script checks all and and disables all checkboxes with a certain ID using an onclick command on one main checkbox. When the user unclicks that box, the checkmarks disappear, but remain disabled. Even if they hit the reset button, the disabled boxes stay.
Javascript:
<script>
function checkAllbase(bx) {
var cbs = document.getElementsByTagName('input');
for(var i=0; i < cbs.length; i++) {
if(cbs[i].id == '1') {
cbs[i].checked = bx.checked;
cbs[i].disabled=true;
}
}
}
</script>

Give each checkbox input that is associated with a package a similar name or class. Without seeing your actual html, supplying sample html below
HTML
<input type="checkbox" class="package1" name="package1[]" value="vacation">
<input type="checkbox" class="package1" name="package1[]" value="bonus">
<input type="checkbox" class="package1" name="package1[]" value="fries">
JS
function togglePackage(isChecked,packageName) {
//Choose one of the two below to use
//Below selects the inputs by the class name
var cbs = document.querySelectorAll("input."+packageName);
//Or Below selects the inputs by the input name
var cbs = document.querySelectorAll("input[name^="+packageName+"]");
for(var i=0; i<cbs.length; i++) {
//Since they are either checked and disabled (both true)
//or unchecked and enabled (both false) we can just use
//isChecked to set both at once.
cbs.checked = isChecked;
cbs.disabled = isChecked;
}
}
//Then somewhere call the togglePackage function
//bx here would be the main checkbox that you want to
//have toggling the other boxes, and "package1" is obviously
//the name or the class you gave the checkboxes.
togglePackage(bx.checked,"package1");

The elements remain disabled because the value being set is a constant (literal) true.
What you can do is copy bx.disabled throughout, as you're doing with bx.checked:
cbs[i].checked = bx.checked;
cbs[i].disabled = bx.disabled;
Or add another argument to pass the desired disabled state:
function checkAllbase(bx, disabled) {
disabled = disabled !== false; // limit to `true` or `false`, prefer `true`
// ...
cbs[i].checked = bx.checked;
cbs[i].disabled = disabled;
// ...
}
// usage
checkAllbase(bx); // disables elements
checkAllbase(bx, true); // also disables elements
checkAllbase(bx, false); // enabled elements

Related

Disabling several elements on one button

I'm trying to toggle disabled status of several element using one button. I did function which only toggle status of one element.
Disabled() {
var element = <HTMLInputElement>document.getElementById("input");
if (element.disabled == true) {
element.disabled = false;
} else {
element.disabled = true;
}
}
what should I change to make it work?
You can bind the input's disabled property to a variable in your code and change that variable on click:
<input ng-disabled="disabled"/>
<button ng-click="disabled = !disabled">
Disable
</button>
Example: https://stackblitz.com/edit/angularjs-n78yrt?file=home%2Fhome.html
Update: Stackblitz changed to work without ng-syntax

AngularJS: set validity do not work when company with updating model in the same function

I am very new to AngularJS and I am trying to make a reset button for my form.
My model is a 2 dimensional array with validity for each cell.
I have to manually set values to null and reset the validity for each cell.
my code:
$scope.clear = function () {
for (var i = 0; i < $scope.nums.length; i++) {
for (var j = 0; j < $scope.nums.length; j++) {
$scope.nums[i][j] = null;
}
}
angular.forEach($scope.myForm.$$controls, function (v, k) {
v.$setValidity('', true);
});
};
and the button:
<input type="submit" ng-click="clear();" value="Clear" />
the problem is after the button is clicked, only the values are cleared and not the validity, but when I click it again (when all the values are cleared), the validity is cleared.
How can I get both of these to happen by clicking the button only once?
In order to reset the form to its original state you can use in your code the $setPristine function which:
Sets the form to its pristine state.
This method sets the form's $pristine state to true, the $dirty state
to false, removes the ng-dirty class and adds the ng-pristine class.
Additionally, it sets the $submitted state to false.
This method will also propagate to all the controls contained in this
form.
Setting a form back to a pristine state is often useful when we want
to 'reuse' a form after saving or resetting it.
Your code would go like this: $scope.myForm.$setPristine().
You might also want to take a look at $setUntouched

angularjs on form edit select option does not load value On Second Time

My form has got 2 select boxes. The second select options box is loaded when an option is selected in first box. The form is used for both adding and editing. I show the list below the form with edit button against each row. When I click on edit button it loads the values in form to edit. The thing is when I click on a row for first time it loads the values in form perfectly. If I click on another row button to edit, the SECOND select option alone does not show the selected value. But the box is loaded with values.
Code in controller:
$scope.editShift = function(row) {
for (var i = 0; i < $scope.availableShift.length; i++) {
if ($scope.availableShift[i].shiftId === row.entity.shiftId) {
$scope.shift = angular.copy($scope.availableShift[i]);
break;
};
};
$scope.selectLineNames();
};
$scope.selectLineNames = function(){
$scope.availableListOfLineNames = [];
$scope.availableListOfLineNamesTemp = LineDetails.ld_get_ln_resource.query
({plant: $scope.shift.plant}, function(response) {
angular.forEach(response, function(item) {
if (item) {
$scope.availableListOfLineNames.push(item);
}
});
});
};
Second Select Option in Form
<select name="lineName" ng-model="shift.lineName"
ng-options="x for x in availableListOfLineNames" id="selectoption2" required>
<option value="">Select One</option>
</select>
EDIT:
Calling $scope.selectLineNames(); inside $scope.editShift somehow makes the lineName value undefined after copy, on second time. Inside selectLineNames() too the value is available until it reaches the forEach() .Only after the loop starts It becomes undefined.
So used a duplicate method like $scope.selectLineNamesTemp(); and passed values from $scope.editShift and assigned them in the duplicate method like below.
$scope.selectLineNamesTemp = function(){
$scope.availableListOfLineNames = [];
$scope.availableListOfLineNamesTemp = LineDetails.ld_get_ln_resource.query(
{plant: plantTemp}, function(response) {
angular.forEach(response, function(item) {
if (item) {
$scope.availableListOfLineNames.push(item);
$scope.shift.lineName = lnTemp; // assigned from editShift
}
});
}) ;
};
Can someone point out why the value become undefined? Also is there a way to use the same old method without using the duplicate method. Hope someone help.

Excel-like behaviour of Grids in Ext JS

I'm trying to figure out a way to have an Excel-like behavior with the Grids on Ext JS.
Here is the sample grid I am working with. So far we can already naviguate through the cells with the arrows but only in edit mode.
However what I am trying to reach is the naviguation with the arrows, TAB and Enter keys outside of the edit mode, just like excel.
I tried to integrate this piece of code which overrides the Editor class, hoping that it would change the behavior of the cells but it doesn't change a thing.
I believe this is the most important part that overrides the Editor class and tries to include the keys input :
Ext.override(Ext.Editor, {
startEdit: function (el, value) {
var me = this,
field = me.field;
me.completeEdit();
me.boundEl = Ext.get(el);
value = Ext.isDefined(value) ? value : me.boundEl.dom.innerHTML;
if (!me.rendered) {
me.render(me.parentEl || document.body);
}
if (me.fireEvent('beforestartedit', me, me.boundEl, value) !== false) {
me.startValue = value;
me.show();
field.reset();
if (deleteGridCellValue) {
field.setValue('');
me.editing = true;
me.completeEdit();
deleteGridCellValue = false; // reset global variable
}
else {
if (newGridCellValue == '') {
// default behaviour of Ext.Editor (see source if needed)
field.setValue(value);
}
else {
// custom behaviour to handle an alphanumeric key press from non-edit mode
field.setRawValue(newGridCellValue);
newGridCellValue = ''; // reset global variable
if (field instanceof Ext.form.field.ComboBox) {
// force the combo box's filtered dropdown list to be displayed (some browsers need this)
field.doQueryTask.delay(field.queryDelay);
}
}
me.realign(true);
field.focus(false, 10);
if (field.autoSize) {
field.autoSize();
}
me.editing = true;
}
}
}
});
This is the first time that I am working on a project that is outside of Comp-Sci classes so any help would be very much appreciated. Thanks !

How can I make a SelectBox required in qooxdoo?

How can I force a user to make a selection from a qooxdoo SelectBox? I would like the SelectBox to initially appear with an empty selection (or better yet, a "Please select..." message). I would like form validation to fail if the user has not made a selection, and the selectBox to appear with the red "invalid" decoration and "required" tooltip, just like a required textField.
Similarly for RadioButtonGroup: is there a way to make the group initially appear with no button selected, and not become valid until a selection is made?
Later... this seems to work for the SelectBox case:
var genderSlct = new qx.ui.form.SelectBox();
genderSlct.add(new qx.ui.form.ListItem("")); // initially selected null item
genderSlct.add(new qx.ui.form.ListItem("Male", null, "M"));
genderSlct.add(new qx.ui.form.ListItem("Female", null, "F"));
...
myForm.getValidationManager().setValidator(function(items) {
var valid = true;
if (genderSlct.getSelection()[0].getModel() == null) {
genderSlct.setValid(valid = false);
genderSlct.setInvalidMessage("Please select your gender.");
}
...
if (valid) {
genderSlct.setValid(true);
...
return true;
} else {
return false;
}
});
Later still... Found a solution for the RadioButtonGroup as well:
To get that initial unselected state, add an invisible first listItem with null model:
myRbg.add(new qx.ui.form.RadioButton("").set({
model: null, visibility: "excluded"
}));
Then add the same style of code as for the selectionBox to the form validator.
Check out this demo which offers exactly which your looking for in the SelectBox case:
http://demo.qooxdoo.org/2.0.1/demobrowser/index.html#data~Form.html
You can simply check for the selection in the validator.

Resources