Dojo: Select of empty value for FilteringSelect while required=false - dojo

Please look on this code:
dojo.require('dijit.form.FilteringSelect');
dojo.require('dojo.store.JsonRest');
dojo.declare('JsonFilteringSelect', dijit.form.FilteringSelect, {
constructor: function (options) {
dojo.declare.safeMixin(this, options);
if (this.url) {
this.store = new dojo.store.JsonRest({
target: this.url
});
} else {
console.log('JsonFilteringSelect: options.url is not defined');
}
}
});
var getPersonJsonFilteringSelect = new JsonFilteringSelect({
url: '/person/get',
name: 'Test',
title: 'Test title',
required: false,
autoComplete:false,
value: '',
pageSize:10,
queryExpr:'${0}'
}, dojo.byId('select'));
getPersonJsonFilteringSelect.startup();
});
Use case: Suppose I have 20 results into my FilteringSelect.
User selects 1 value of FilteringSelect.
This value set as value of
FilteringSelect.
But after user decides to change this value on
empty value.
As I understand, because required:false FilteringSelect should allow
to set empty value, but it is not. I observe this behavior here:
User clicks FilteringSelect textbox
User clears it
While user presses "Tab" or clicks by other element - FilteringSelect automatically selects first value.
How could I allow user to set empty value into FilteringSelect?

You should add an empty entry ("" or null maybe? I know "" works) to your data store after it's loaded (I'd put it at the beginning) but before startup of the widget.
The "required" issue is strange with FilteringSelect because it won't let you select any arbitrary value -- it has to be an entry from the data store. Yet, if it's not required shouldn't it not care?... Dojo is strange sometimes.

Related

DataTables does not save state of date range search

I am using data tables to display a list of events of different types. Besides the default global text search I need to
1. filter list by event type
2. filter list by date range (show only today -> infinity)
3. Save the state of the table for the the current session.
The state saves as expected except for the date range search which is always reset. Am I missing something or custom search functions are out of the scope of state saving? Here's the relevant code in jQuery:
Fist I add my own search function through the provided method. This works except it's state is not saved
// Extend search()
var threshold_timestamp = xxxxxxxxxxxx // set for beginning of today)
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex) {
var timestamp = parseInt(data[1]); // event date timestamp
if (timestamp > threshold_timestamp) {
return true;
}
return false;
}
);
Then I add a listeners for the select used to switch between the event type options ('','Event','Sports','Dance'...) and the button user to turn on/off the date range filter
$('#filter-by-type').on('change', function() {
table.columns(0).search( $(this).val() ).draw();
});
$('#dt-history').on('click', function() {
// Logic to toggle threshold_timestamp between 0 or value
table.draw();
});
Then I call DataTables
var table = $('#example').DataTable( {
ajax: "datasource.json",
stateSave : true,
stateDuration: -1,
columns: [
{ data: "type"}, //str as 'Sport','Dance'
{ data: "date"} // int as 1528572000
]
});
I managed to scratch my head sideways and "save the date search" using localstorage but that is a hack. On page load I trigger a button click to execute the search so initially the tables seems empty, the "No data available in table" message appears and then the filtered results display. As a second hack I will suppress that message so when there will really be no data... there will be no message :(

KeystoneJS dependsOn not saving its new value when disappear

User.add({
name: { type: Types.Name, required: true },
userid: { type: Types.Text, initial: true, required: true },
exceed_login_attempt: {
type: Types.Boolean,
default: false,
label: 'Exceeded Invalid Login Attempts',
dependsOn: { exceed_login_attempt: true }
}
});
I have here a checkbox input field exceed_login_attempt I want this to be display in AdminUI if the value is true (checked). If I unchecked that the value is false and the checkbox will disappear - this is fine.
But when I save it the checkbox value which is false is not save. After rendering the page the value is still true, which means it displays again the checkbox.
On KeystoneJS database documentation it is mentioned that:
To improve the usability of the Admin UI, it is possible to hide fields when no value is set, or depending on the value of other fields.
A field can depend on the value of other fields. But in your posted code, the exceed_login_attempt field, depends on its own value, which doesn't look right to me:
exceed_login_attempt: {
...
dependsOn: { exceed_login_attempt: true }
}
I'm not sure, maybe you intend to use collapse rather than dependsOn:
collapse [Boolean] Displays an + add link in the admin UI when the field has no value. Will completely hide field UI when noedit is also set to true, when the field has no value

Set Value on dijit/form/FilteringSelect after its already been created

I have FilteringSelect using a MemoryStore. When a user types a value that is not in the store, they are prompted, asking if they would like to add the new value to the store.
If they do, we call the server, create the new item, and on the response, we publish an event.
The topic subscriber is notified that a new item was created and added to the MemoryStore, which adds the option to the filteringselect.
At this point, the filtering select still has the same displayValue, and the option exists in the select. FilteringSelect.get("value") still returns "".
If you were to type a space, then hit backspace, (ending up with the same value), FilteringSelect.get("value") would return the correct item id.
FilteringSelect.set("value", data[0].id) doesn't do anything, no exception thrown, no affect.
Here's the code, contains some of the random calls I tried.
require(["dojo/store/Memory", "dojo/_base/array", "dojo/topic"],
lang.hitch(this, function(Memory, array, topic) {
this.liftStore = new Memory({
data: []
});
array.forEach(data, lang.hitch(this, function(entry, i) {
this.liftStore.data.push({
name: entry.Name,
id: entry.ID,
identifier: entry.ID
});
}));
this.lift.set("store", this.liftStore);
topic.subscribe("LiftLog/NewLift", lang.hitch(this, function(data) {
debugger;
data[0].selected = true;
data[0].identifier = data[0].id;
this.liftStore.data.push(data[0]);
this.lift.reset();
this.lift.set("value", data[0].id);
this.lift.set("value", data[0].id.toString());
}));
}));
Have you tried setting the item (i.e. filteringSelect.set("item", newItem) instead of setting the value? Note that you should give it the whole item, not just the id or the displayed value.
So, push the item into the store, and then set the item on the FilteringSelect:
this.liftStore.data.push(newItem);
this.lift.set("item", newItem);

Row Expander checking condition

I have Grid with "rowexpander". with this I am able to expand the row, and able to show the content .i.e. html checkbox.
Now my requirement is the in my DB I got the value true or false. So depending upon the value i.e. true I want show check box with checked.
Here is my code.
plugins: [
{
ptype: 'rowexpander',
rowBodyTpl:
['<ul><li><input type="checkbox" name="" checked={marginAccess} ><span>Margin Access for Quote</span></li></ul> ']
}
Now {marginAccess} when is it true I want to show ""
i.e. checked = checked
I am not able to do this, Can you please suggest me ?
Create a virtual member in your model. One which will return 'checked/unchecked' for true/false value of other field. Like this:
{ name: 'marginAccess_str', type: 'string', convert: function(v, r) {
if (r.get('marginAccess'))
return 'checked';
else
return 'unchecked';
}},
And then use marginAccess_str in your template.

How to avoid the first-line automatic selection after inserting a new row to the store of a grid

I am using extjs4 to create a gird which can be editable by the "Ext.grid.plugin.CellEditing" plugin.
When the user click the "Add" button. It will add a new row to the store for user input. But after the insertion, first row of the grid will be selected automatically. So the cell editor lose the focus everytime.
Related code below:
var cellEditing = Ext.create('Ext.grid.plugin.CellEditing');
// part options for grid
selType: 'cellmodel',
selModel: Ext.create('Ext.selection.CheckboxModel', { checkOnly: true }),
plugins: [cellEditing],
// Add new record
var r = Ext.ModelManager.create({
id: '',
name: '',
label: '',
description: ''
}, 'Privilege');
pstore.insert(0, r);
cellEditing.startEditByPosition({
row: 0,
column: 1
});
i try, won't lose focus of input text.
but my code is
var r = Ext.create('PlcModel', {
//eqNo:Ext.create('Ext.grid.RowNumberer'),
slavePos:'aa:bb:cc:dd:ee:ff',
eqdesc: 'Mostly Shady',
eqmanu: 'TL-PA201',
onlineSt: false,signal:0,
bandwidLimit:512,
hardwareversion:'V.93.344.0',
enabled:false,vlanid:105
});
var curStore=Ext.data.StoreManager.lookup('PLCTeams');
var len= curStore.count();
curStore.insert(len+1, r);
cellEditing.startEditByPosition({row: len, column: 1});
CheckboxModel choose but focus input also exist, you can input
pls not email me, since my login info input wrong for secret
my extjs4 version is 4.0.7