Kendo grid schema.model.fields field validation on keypress? - kendo-grid

Instead of creating functions and calling those, can I trigger the Kendo Grid schema > model > fields > my_field > validation when a key is pressed in the input fields?
schema: {
model: {
fields: {
field: { type: "string",
validation: {
ifieldValidation: function (input) {
// My code here. Instead of putting all this in separate function can I trigger this validation somehow?
return true;
}
return true;
}
},
},
... more fields
$("#myselector").on("keydown", ".input-field", function (e) {
// instead of creating functions and calling those, can I trigger the Kendo Grid schema > model > fields > my_field > validation for example call the ifieldValidation ?
});

I just found the solution, so I'm answering my question in case someone needs this too:
$("#mygrid").on("keydown", ".my-input", function (e) {
mygrid.options.schema.model.fields.myfieldname.validation.mycustomvalidationfunction($(this));
});

Related

How do I bind data to an element created with this.$createElement

I created an InfoWindow from Google maps and I want to put a vue component (specifically an input) inside the content property and bind it to a data. I'm also using vuetify and if possible, I want to use it's VTextfield component. If not, then a regular input would be ok as well.
Example:
data
data () {
return {
inputVal: null
}
}
methods
renderInfoWindow () {
let input = /* create an input and bind it to inputVal */
return new google.maps.InfoWindow({
content: input
})
}
According to the Template Compilation section in the docs,
<input v-model="inputVal">
is this render function:
function anonymous(
) {
with(this){
return _c('input', {
directives: [{
name: "model",
rawName: "v-model",
value: (inputVal),
expression: "inputVal"
}],
domProps: { "value": (inputVal) },
on: {
"input": function($event) {
if ($event.target.composing)
return;
inputVal=$event.target.value
}
},
})
}
}
I haven't used render functions yet, so I hope this is what you need.

Sequelize findOrCreate not excluding attributes defined in the exclude array

Following is the code:
Accounts.findOrCreate({
where: {
userName: request.payload.userName
},
attributes: { exclude: ['password','sessionToken'] },
defaults: request.payload
}).spread(function (account, created) {
if (created) {
var account = account.get({
plain: true
});
console.log(account); // has the password and sessionToken fields
return reply(account).code(201);
} else {
return reply("user name already exists").code(422);
}
});
I noticed that sequelize first fires a select query in which the password field is not present, then it fires an insert statement in which the password field is present, and that needs to be there.
I would just like the password and sessionToken not be present in the resulting account object. I could of course delete those properties from the object but I am looking for a more straightforward way.
It seems like you need to delete those fields manually. According to the source code, findOrCreate method first fires the findOne function and then it goes with create if instance was not found. The create method does not accept attributes parameter. In such a case all fields will be returned.
Good solution would be to create instance method in the Accounts model in order to return an instance with only the desired attributes.
{
instanceMethods: {
toJson: function() {
let account = {
id: this.get('id'),
userName: this.get('userName')
// and other fields you want to include
};
return account;
}
}
}
Then you could simply use the toJson method when returning raw representation of object:
Accounts.findOrCreate({ where: { userName: 'username' } }).spread((account, created) => {
return account ? account.toJson() : null;
});
As mentioned by piotrbienias you can follow his way otherwise just delete the unwanted elements like this:
Accounts.findOrCreate({
where: {
userName: request.payload.userName
},
defaults: request.payload
}).spread(function (account, created) {
if (created) {
var account = account.get({
plain: true
});
delete account.password;
delete account.sessionToken;
console.log(account); // now you don't have the password and sessionToken fields
return reply(account).code(201);
} else {
return reply("user name already exists").code(422);
}
});

Autodesk Forge Viewer3d search using attributeNames

I'm trying to implement .search() and restrict attributeNames using the optional parameter but it always brings back an empty array.
https://developer.autodesk.com/en/docs/viewer/v2/reference/javascript/viewer3d/
Can someone clarify how this filter is being applied? I was expecting it to look at the returned property.displayName but apparently that's not the case.
Example:
viewer.search('13-097', function (ids) {
console.log(ids);
var id = ids[0];
viewer.getProperties(id, function (obj) {
console.log(obj.properties);
});
}, function (e) { });
viewer.search('13-097', function (ids) {
console.log(ids);
}, function (e) { }, ['ADDRESS']);
Output:
first search:
[8095]
second search:
[]
from object 8095, properties:
10:Object
displayCategory:"DWF - Construction"
displayName:"ADDRESS"
displayValue:"13-097"
hidden:false
type:20
units:null
Please note the Autodesk.Viewing.Viewer3D.search() method is NOT case sensitive on the text parameter, but it IS case sensitive on the attributeNames parameter, and you need to use the full name of the attribute.
If you are using the displayName of properties to correlate, note that viewer.getProperties() is currently returning the displayName. When there is no displayName, then (and only then) attribute name is returned.
Below is a sample I tried before (adjusted to your dataset):
function search() {
viewer.clearSelection(); // remove previously highlighted searches
var searchStr = '13-097';
var searchPropList = new Array('ADDRESS');
viewer.search(searchStr, searchCallback, searchErrorCallback, searchPropList);
}
function searchCallback(ids) {
alert(ids.length);
}
function searchErrorCallback(error) {
console.log(error);
}
EDIT (Oct 24, 2016)
The Viewer 2.11 .getProperties method returns attributes, which can be used on the .search attributesNames parameter.

Kendo Grid Inline MultiSelect - Posted Values

I'm replicating the functionality very close to what's seen here. https://onabai.wordpress.com/2013/07/17/kendoui-multiselect-in-a-grid-yes-we-can/
I have Kendo grid with an inline multiselect editor field. I have a datasource.sync() event kicked off on change of that multiselect. The issue I'm having is how the data is arranged in the post variables.
I'm using FireBug in FireFox. I can set a function to view the values in my multiselect field like this at the sync() event.
console.log(this.value());
This would be for a string array field I have called "RoleCode". Anyway, the console log displays the values as they should, for example
A, OU
However, when I look in the Post call to my controller and at the parameters, I see the RoleCode field is duplicated, which is why my controller doesn't recognize the method signature. For example, this is what I see in FireBug...
ID 123
Field1 TextFromField1
RoleCode[1][RoleCode] OU
RoleCode[] A
Any idea how I should set this up so the post parameters are usable?
UPDATE
For now I just altered the update function to send the multiselect values as a comma separated string. I can deal with them in the controller. I don't really like this setup, but until I find how to get the posted values to send correctly, this is what I'm going with.
update: {
url: "Home/GridUpdate",
type: "POST",
dataType: "json",
data: function () {
//Grid does not post multiselect array correctly, need to convert to a string
var rolesString = $("#gridRoleList").data("kendoMultiSelect").value().toString();
return { rolesString: rolesString };
},
complete: function (e) {
setTimeout(function () {
refreshGrid();
}, 300);
},
success: function (result) {
// notify the data source that the request succeeded
options.success(result);
},
error: function (result) {
// notify the data source that the request failed
options.error(result);
}
},
UPDATE 2
Actually that's not a good idea because if I edit another field in the grid, I get a js error because the multiselect is not found.
Looks like your issue can be resolved by sending the data after serializing it
Read action - using MVC Wrapper
.Create(create => create.Action("Create", "Home").Data("serialize"))
JS Code
<script type="text/javascript">
function serialize(data) {
debugger;
for (var property in data) {
if ($.isArray(data[property])) {
serializeArray(property, data[property], data);
}
}
}
function serializeArray(prefix, array, result) {
for (var i = 0; i < array.length; i++) {
if ($.isPlainObject(array[i])) {
for (var property in array[i]) {
result[prefix + "[" + i + "]." + property] = array[i][property];
}
}
else {
result[prefix + "[" + i + "]"] = array[i];
}
}
}
</script>
Please refer here for complete source code
Here's how I solved it. On the change event of the editor function, I updated the value of the model with the value of the multiselect. Then the data posts correctly as a string array like this.
ID 123
Field1 TextFromField1
RoleCode[] A
RoleCode[] OU
My grid editor function
function roleMultiSelectEditor(container, options) {
$('<input id = "gridRoleList" name="' + options.field + '"/>')
.appendTo(container)
.kendoMultiSelect({
dataTextField: "RoleCode",
dataValueField: "RoleCode",
autoBind: true,
change: function (e) {
//Applies the value of the multiselect to the model.RoleCode field
//Necessary to correctly post values to controller
options.model.RoleCode = this.value();
processGridMultiSelectChange();
},
dataSource: {
type: "json",
transport: {
read: {
dataType: "json",
url: baseUrl + "api/DropDownData/RoleList",
},
}
},
dataBound: function (e) {
}
});
}

Extjs5 model default values in ajax request

I have a problem. I created a simple model and tried to save new value by using it through ajax request. But parameters which must be empty sends default value. You can see it by link under. The code does not specifically set the correct way bacause of what the console(f12) can be seen fallen challenge. In it I pass a value through a query-string, as well as through the payload-request (not yet invented how to get rid of it, as I understand it-payload is used by default). In general, instead of an empty carId call transfers Car-1.
https://fiddle.sencha.com/#fiddle/dsj
How do I fix this behavior and do that if we do not share any meaning, it passed empty?
You can create your custom proxy class that extends Ext.data.proxy.Ajax and then override buildRequest method to check for all create actions and to assign desired value to idProperty
Ext.define('CarProxy', {
extend: 'Ext.data.proxy.Ajax',
alias: 'proxy.carproxy',
type: 'ajax',
idParam: 'carId',
reader: {
type: 'json',
rootProperty: 'data'
},
api: {
create: './createcar.json'
},
writer: {
type: 'form'
},
buildRequest: function(operation) {
var request = this.callParent(arguments);
if (request.getAction() === 'create') {
request.getRecords().forEach(function(record) {
record.set('carId', ''); //assing desired value to id
});
}
return request;
}
});
Thanks everyone who answered. I want to show my solution:
add to model definition parameter
identifier: 'custom' .
And then create appropriate identifier which will return undefined on generate method:
Ext.define('Custom', {
extend: 'Ext.data.identifier.Generator',
alias: 'data.identifier.custom',
generate: function() {
return;
}
});
This is default ExtJS behaviour. If you do not specify id, it is generated. To avoid that you can for add constructor to your model:
Ext.define("Car", {
[...],
constructor: function() {
this.callParent(arguments);
// check if it is new record
if (this.phantom) {
// delete generated id
delete this.data[this.idProperty];
}
}
});