I have a checkbox on my form panel,
And I'm on the process where I need to edit a data based on id in MySQL database where there is a option for checkbox 1=checked 0=not checked,
how do I get the value of, for example, the field of checkbox and put it on a conditional clause and set the value checked to checkbox if it is 1 and not checked if it returns 0?...
Need to set to the checkbox config
inputValue: '1',
uncheckedValue: '0'
You can check the documentation at http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.form.field.Checkbox-cfg-uncheckedValue
All checks do not consider the event check if the value is a string. I created a fix. Add before Ext.onReady
Ext.override
(
Ext.form.Checkbox,
{
setValue:function(v){
var checked = this.checked, inputVal = this.inputValue;
if(v === false)
{
this.checked = false;
}
else
{
this.checked = (v === true || v === 'true' || v == '1' || (v instanceof String) || (inputVal ? v == inputVal : String(v).toLowerCase() == 'on'));
}
if(this.rendered)
{
this.el.dom.checked = this.checked;
this.el.dom.defaultChecked = this.checked;
}
if(checked != this.checked)
{
this.fireEvent('check', this, this.checked);
if(this.handler)
{
this.handler.call(this.scope || this, this, this.checked);
}
}
return this;
}
}
);
{
xtype:'checkbox',
fieldLabel:'Caption',
labelSeparator:':',
boxLabel:'LabelText',
name:'status',
inputValue:'0'
}
inputValue must be a String '0'.
this issue has been resolved,
by using 1 checkbox per field, there is no problem at all!....
the checkbox will get checked when the fieldname assigned to it returns a value of 1,
that's it!,
....
Related
The combobox in modern fires the "select" event every time the input changes. This is very different from classic. With it doing this there is no way to differentiate between a user making a selection and pragmatically setting the value of the field.
This was reported as a bug in the Sencha forums:
https://www.sencha.com/forum/showthread.php?468730-Modern-6-5-2-ComboBox-fires-select-event-on-every-value-change
The link above also contains a fiddler to demonstrate the issue.
Has anyone run into this as an issue, and how did you overcome it?
forceSelection: true will help to solve this problem but will not cancel the bug in cases when forced selection is not needed
Edit:
This behavior is due to method syncValue (search in this source - method is private and hasn't documentation)
I don’t understand why the component developer chose to create a record even if it isn’t exist.
Comment from source file:
Either user has typed something (isInput), or we've had a setValue to a value which has no match in the store, and we are not forceSelection: true. We create a new record.
I propose to fix this behavior using the following override:
fiddle
Ext.define('Ext.field.SelectOverride', {
override: 'Ext.field.Select',
autoCreateRecord: false,
syncValue: function() {
var me = this,
store = me.getStore(),
forceSelection = me.getForceSelection(),
valueNotFoundText = me.getValueNotFoundText(),
is, isCleared, isInput, value, matchedRecord;
if (me.reconcilingValue || !store || !store.isLoaded() || store.hasPendingLoad()) {
return;
}
me.reconcilingValue = true;
me.getSelection(); // make sure selection config is flushed
is = {};
is[me.syncMode] = true;
value = ((isInput = is.input || is.filter)) ? me.getInputValue() : me.getValue();
isCleared = value == null || value === '';
if (!isCleared) {
if (me.getMultiSelect()) {
return me.syncMultiValues(Ext.Array.from(value));
}
matchedRecord = (isInput ? store.byText : store.byValue).get(value);
if (matchedRecord) {
if (!matchedRecord.isEntity) {
matchedRecord = matchedRecord[0];
}
}
else if (!forceSelection) {
matchedRecord = me.findRecordByValue(value);
}
}
// Either user has typed something (isInput), or we've had a setValue
// to a value which has no match in the store, and we are not forceSelection: true.
// We create a new record.
if (!isCleared && !matchedRecord && !forceSelection && me.autoCreateRecord) {
matchedRecord = me.createEnteredRecord(value);
}
else {
if (isInput || is.store) {
if (!matchedRecord && forceSelection) {
me.setValue(null);
me.setSelection(null);
if (!is.filter) {
me.setFieldDisplay();
}
}
} else {
if (isCleared) {
if (me.mustAutoSelect()) {
matchedRecord = store.first();
if (me.getAutoSelect() === 'initial') {
me.setAutoSelect(false);
}
}
else {
me.setSelection(null);
}
}
else if (!matchedRecord && valueNotFoundText) {
me.setError(valueNotFoundText);
}
}
}
if (matchedRecord) {
me.setSelection(matchedRecord);
}
me.reconcilingValue = false;
}
});
I am saving a record on button click but it always throwing an error.
I am including an if else condition. I have surpassed all the conditions but still my code is going to the if condition but It should not go to if condition.
code is -
my this.state.question.options value is -
[
{
id:3250,
label:'good answer',
assert:1
position:1
},
{
id:3249,
label:'bad answer',
assert:0
position:2
}
]
and I am checking if else condition as -
if (this.state.question.options.filter(o => o.assert === true).length <= 0) {
hasError = true
errorKey = 'add-question-modal-missing-assert-options'
}
else {
alert("test");
}
my code should goto else part and print test as alert but it is going to if part and showing error. Why ?
I wanna show else part i.e test as alert
You are using the strict comparison operator (===) while comparing 2 different values. In your example, 1 is being parsed as an integer, while true is being parsed as a boolean. A strict comparison operator is used to check 2 values on equal values AND equal types.
To fix the error in your code, use a loose comparison (==) or convert the integer to a boolean by using !!1
if (this.state.question.options.filter((el) => {return !!el.assert}).length <= 0) {
hasError = true
errorKey = 'add-question-modal-missing-assert-options'
}
else {
alert("test");
}
In JavaScript, 1 is not strictly equal to true. However, it is a good practice to use the strict equality operator ===.
You should compare o.assert with the real possible value o.assert === 1.
In terms of readability I would also consider comparing the length to 1 instead of 0:
this.state.question.options.filter(option => option.assert === 1).length < 1
this.state.question.options value is -
[
{
id:3250,
label:'good answer',
assert:1,
position:1
},
{
id:3249,
label:'bad answer',
assert:0,
position:2
}
]
and then
if (this.state.question.options.filter(o => o.assert == true)).length <= 0) {
hasError = true
errorKey = 'add-question-modal-missing-assert-options'
} else {
alert("test");
}
replace === strict type with ==
Do u want this kind of code
if (this.state.question.options.length <= 0) {
assert = true;
hasError = true;
errorKey = 'add-question-modal-missing-assert-options'
}
else {
alert("test");
}
I'm stuck on this ExtJS grid date filtering and will really appreciate some help.
My goal is to remove the "Before" and "After" submenu items and to show only the "On" item (even better is to remove the entire submenu and just show the datepicker).
So my question is if it's possible to remove those items and how can I do it?
I tried with the menuItems config menuItems: ['eq'] and this works visually, but when I select some date from the datepicker I receive this error Uncaught TypeError: Cannot read property 'up' of undefined.
Sencha Fiddle
Thanks!
There is a problem in the Date filter component on the "onMenuSelect", it tries to unselect both "before" and "after" menu itens if you choose the "on" option, but you had those removed in the config.
I did a little override to fix this:
Ext.override(Ext.grid.filters.filter.Date, {
onMenuSelect: function(picker, date) {
var me = this,
fields = me.fields,
filters = me.filter,
field = fields[picker.itemId],
gt = fields.gt,
lt = fields.lt,
eq = fields.eq,
v = {};
field.up('menuitem').setChecked(true, /*suppressEvents*/
true);
//The problem ocurrs here, i modified this line
//if (field === eq) {
//**********************************************
if ((field === eq)&&(lt!=null)&&(gt!=null)) {
lt.up('menuitem').setChecked(false, true);
gt.up('menuitem').setChecked(false, true);
} else {
eq.up('menuitem').setChecked(false, true);
if (field === gt && (+lt.value < +date)) {
lt.up('menuitem').setChecked(false, true);
if (filters.lt.getValue() != null) {
v.lt = null;
}
} else if (field === lt && (+gt.value > +date)) {
gt.up('menuitem').setChecked(false, true);
if (filters.gt.getValue() != null) {
v.gt = null;
}
}
}
v[field.filterKey] = date;
me.setValue(v);
picker.up('menu').hide();
}
});
I have a deeply nested object. I have some records which contain 2 fields that show keys of object properties. I also have select needed to search records by property of object and input to search by key of object. So if I choose option1 and type in input some text, it will be shown the matches in the first field (not second!). And it's similar for second field.
How I try to realize:
I wrote a filter http://plnkr.co/edit/z9DEmfYz2grW9UonLcFK?p=preview
.filter('appFilter', function() {
return function(value, select, input) {
var result = [];
input = input.toLowerCase();
var reg = new RegExp(input,'g');
if (angular.isArray(value)) {
if (input === '' || $scope.isFiltering) {
return value;
} else if (select.value === 'Sequence') {
for (let i = 0; i < value.length; i++) {
if (value[i].Sequence.toLowerCase().match(reg)) {
result.push(value[i]);
}
}
return result;
} else if (select.value === 'ID') {
for (let i = 0; i < value.length; i++) {
if (angular.isArray(value[i].Document)) {
for (let j = 0; j < value[i].Document.length; j++) {
if (value[i].Document[j].ID.toLowerCase().match(reg)) {
result.push(value[i]);
}
}
}
}
return result;
} else {
console.log('error');
}
}
}
})
In controller I set to select's ng-model first option: $scope.selectParameter = $scope.parameter[0];
In debug I set to input parameter some value (123 for example).
So I searching record by first field that contains 123 value. And result finds and pushes the object. But in browser shows anything.
What's the problem? And I can't avoid the empty option with '?' value in my select :(
UPDATED
Nearly solve my problem: http://plnkr.co/edit/z9DEmfYz2grW9UonLcFK?p=preview
It filters by appropriate field and input value. But I faced with another troubles.
When input is empty it doesn't show any record. And second is when I choose second option (ID) filter duplicates some records.
Also I try to switch off filter without clearing the input text by clicking on checkbox.
It's what I want to do but it doesn't work:
else if (input === '' || $scope.isFiltering) {
return value;
}
$scope.isFiltering is ng-model for checkbox input
I tried using angulars default filter. I'm not sure if this is exactly what you want, but maybe it helps a little.
.filter('appFilter', function($filter) {
return function(value, select, input) {
if( !angular.isDefined(input) || input.length < 1) {
return value;
}
// Angulars "filter" lets you pass in a object-structure to search for nested fields.
var query =
(select.value === 'Sequence') ?
{Sequence:input} : {Document:{ID:input}};
return $filter('filter')(value, query);
}
})
http://plnkr.co/edit/Egkw9bUvTPgooc0u2w7C?p=preview
I was asked to change some code using lodash's _.every:
//for every item in collection, check if "someProp" is true,
//but only if "someProp2" isn't "-1". If "someProp" is true for
//every item in collection, return true.
$scope.areAllTrue = function() {
for(var i=0; i<$scope.collection.length; i++){
if($scope.collection[i].someProp2 === -1) {
continue;
}
if(!$scope.collection[i].someProp) {
return false;
}
}
return true;
};
So following the lodash example of:
_.every(users, 'active', false);
We get:
$scope.areAllTrue = function() {
return _.every($scope.collection, 'someProp', true)
};
This handles the "For every item in the collection, check if someProp is true, if all are true, return true." But can I do the "continue" check here somehow?
Edit: Can I use two predicates with "_.every" somehow? Like if someProp1 === true || someProp2 === -1 ?
_.every() can use a predicate function:
_.every(users, function(user) {
return user.someProp2 === -1 || user.someProp;
});
You can also skip lodash, and use Array.prototype.every:
users.every(function(user) {
return user.someProp2 === -1 || user.someProp;
});