KeystoneJS dependsOn not saving its new value when disappear - keystonejs

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

Related

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

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.

Jquery validation in IE 8 - Object doesn't support this property or method for drop down box

I'm using jquery validation to validate my form. It works well on text box but when I try to validate a drop down, it throws me an "Object doesn't support this property or method" error in IE 8 only. It works fine in FF or Chrome. Not sure if I did something wrong. I even try not to use the custom "notEqual" function to test it and replace it with the build in "required" method. Again, it's giving me the same thing.
Please help! Much appreciate!
Here's my code:
$(document).ready(function () {
jQuery.validator.addMethod("notEqual", function(value, element, param) {
return this.optional(element) || value != param;
}, "Please specify a different (non-default) value");
$("#form1").validate({
focusInvalid: false,
focusCleanup: true,
debug: false,
onkeyup: false,
onclick: true,
onsubmit: true,
onkeyup: false,
rules: {
<%=titleText.UniqueID %>: {
required: true
},
<%=startDateText.UniqueID %>: {
required: true ,
date: true
},
<%=endHourText.UniqueID %>: {
notEqual: "00"
},
submitHandler: function(form) {
form.submit();
}
},
messages: {
<%=titleText.UniqueID %>: {
required: "Please provide a name for the event."
},
<%=startDateText.UniqueID %>: {
required: "Please enter a date for the event.",
date: "Please enter a valid date."
},
<%=endHourText.UniqueID %>: {
notEqual: "Please enter a valid end time."
}
}
});
});
Thanks in advance!!
Aha, I found this out the hard way myself just the other day. JQuery Validator attempts to access the 'form' property of the select element and if this is null, JQuery Validator blows up with the error you have described.
I'm not entirely sure why element.form would be null for you. I was never entirely clear why it was null for me either, unless it was related to the fact that validation was firing even as the HTML containing this particular select element was being removed from the DOM.
I solved this by adding a check to my validation code so that I only validate a select element where element.form != null. You may also need to check that element.form exists as in Firefox there's no such property:
if (element.form && element.form != null) { ... }

rally search user by first character

I want to realize the functionality that we can search the users' name by typing in the first character of their names. I need to use Javascript to create a custom html.
Is there anyone who has done this before could help me?
In the example from this repository, a user combobox Rally.ui.combobox.UserComboBox searches for matching values dynamically based on the first couple of characters.
This default functionality displays the expected values after the second character is entered.
var u = Ext.create('Rally.ui.combobox.UserComboBox',{
id: 'u',
project: project,
fieldLabel: 'select user',
listeners:{
ready: function(combobox){
this._onUserSelected(combobox.getRecord());
},
select: function(combobox){
this._onUserSelected(combobox.getRecord());
},
scope: this
}
});
this.add(u);
},
If you want to load all users (do not limit the selection to team members and editors of a specific project) you may use Rally.ui.combobox.Combobox instead of Rally.ui.combobox.UserComboBox, and set the model to User. But to workaround a default behavior where only the current user populates the combobox, use a filter that would filter in all users. In the example below ObjectID > 0 is used. This combobox will be populated by all users independently of the project picker. This fragment is not a part of a custom app example above:
{
xtype: 'rallycombobox',
fieldLabel: 'select project',
storeConfig: {
autoLoad: true,
model: 'User',
filters:[
{
property: 'ObjectID',
operator: '>',
value: 0
}
],
sorters: [
{
property: 'UserName',
direction: 'ASC'
}
]
}
}
You'll want to use the Web Services API. Here's how I would do it...
The API doesn't allow you to specify a placement of a character in the filter, but you can require that it exists somewhere in the name, that filter would look like:
[{
property : "FirstName",
operator : "contains",
value : "A" //Whatever letter you're looking to start with
}]
Now, once the store is loaded, use a second function to filter the records to only those which start with your character:
store.filterBy(function(item) {
return item.get("FirstName")[0] === "A";
});
Hope this helps :)

BB10 Cascades SystemDialog

I have a question about SystemDialogs? I need to implement one in QML, but the sample project (“dialogs”) available on Github appears as containing errors when built with the 10.1 SDK. They do however run normally.
The code of interest is as follows:
SystemDialog {
id: dialog
title: qsTr("DIALOG")
body: qsTr("Dialog body")
confirmButton.label: qsTr("Okay button")
confirmButton.enabled: true
cancelButton.label: qsTr("Cancel button")
cancelButton.enabled: true
buttons: [
SystemUiButton {
id: random
label: qsTr("RANDOM")
enabled: true
},
SystemUiButton {
id: random2
label: qsTr("RANDOM2")
enabled: true
}
]
…
}
The “error” properties are the label and enabled properties of the confirm and cancel buttons and the buttons array property of the SystemDialog. As mentioned, although the IDE highlights them as errors, the code appears to work as expected.
My question is, is there a way to do something similar in SDK10.1? I need to set the text on the buttons in the dialog.
The names 'label' and 'enabled' are correct.
You can check bbndk-10.1/target_10_1_0_1020/qnx6/usr/include/bb/system/SystemUiButton.hpp
I think the IDE is not correct in regarding those names as an error.

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.