How to dynamically change validators at runtime - formvalidation-plugin

Let's say I have this validation in one field:
between: {
min: 50,
max: 500,
message: 'Please enter correct range'
}
I would like to update min and max at runtime.
How can I do that ?
Thanks.

You can do that using the updateOption method.
See the following code:
$('#yourForm')
// Update min & max options
.formValidation('updateOption', 'yourInputName', 'between', 'min', 10)
.formValidation('updateOption', 'yourInputName', 'between', 'max', 90)
// Update message if you need to
.formValidation('updateOption', 'yourInputName', 'between', 'message', 'Your new message')
// You might need to revalidate field
.formValidation('revalidateField', 'yourInputName');
# Working example:
http://jsfiddle.net/Arkni/241jzc46/
# Refferences:
updateOption docs: http://formvalidation.io/api/#update-option

Related

How to use gt/le operator in aurelia slickgrid with Odata

I want to send my own operator in odata request and not use the aurelia slickgrid inbuilt "eq" operator.
This is my column definition
{
id: 'LockoutEndDateUtc', name: 'Status', field: 'LockoutEndDateUtc', minWidth: 85, maxWidth: 95,
type: FieldType.boolean,
sortable: true,
formatter: Formatters.multiple,
params: { formatters: [this.StatusFormatter, Formatters.checkmark] },
filterable: true,
filter: {
collection: [
{ value: 'le ' + (() => {const dt = new Date(); return dt.toISOString().split('.')[0] + "Z";})(), label: 'True' },
{ value: 'gt ' + (() => {const dt = new Date(); return dt.toISOString().split('.')[0] + "Z";})(), label: 'False' }
], //['', 'True', 'False'],
model: Filters.singleSelect,//multipleSelect//singleSelect,
}
}
This is the UI
This is how the request filter looks like..
$filter=(LockoutEndDateUtc%20eq%20le%202022-06-28T12%3A59%3A25Z)
If i remove %20eq from the above request, everything else works. So my question is how to i remove %20eq. Or how do i send my own gt, le in the request.
You can't really do that on a boolean filter (you could however do it on a date filter with operator) and I don't think I've added any ways to provide a custom filter search the way you want to do it, but since you're using OData, you have a bit more control and you could change the query string yourself. To be clear, it's not at all recommended to change the OData query string, it's a last solution trick and at your own risk, but for your use case it might be the only way to achieve what you want.
prepareGrid() {
this.gridOptions = {
// ...
backendServiceApi: {
service: new GridOdataService(),
process: (query) => this.getCustomerApiCall(query),
} as OdataServiceApi
};
}
}
getCustomerApiCall(query: string) {
let finalQuery = query;
// in your case, find the boolean value from the column and modify query
// your logic to modify the query string
// untested code, but it would probably look similar
if (query.includes('LockoutEndDateUtc%20eq%20true')) {
// calculate new date and replace boolean with new date
finalQuery = query.replace('LockoutEndDateUtc%20eq%20true', 'LockoutEndDateUtc%20le%202022-06-28T12%3A59%3A25Z');
}
return finalQuery;
}
Another possible solution but requires a bit more work.
If I'd be using a regular grid, without backend service and without access to the query string, I would probably add an external drop down outside of the grid and also add the date column and then control filters in the grid by using dynamic filtering. You can see a demo at Example 23, the principle is that you keep the column's real nature (date in your case) and filter it, if you want something like a "below today's date" then add an external way of filtering dynamically (a button or a drop down) and control the filter dynamically as shown below (from Example 23)

odoo validation error when trying to create a stock.move from onchange function

So i want to automatically create a move line (move_lines) in stock.picking from an #onchange function. Here's my function : It's just a small test. When the value of the field changed change, i take it as the id of the product (product_id) in the move line and then append that move line to the already existing list of move_lines.
NB1:move_lines is a One2many relation in stock.picking.
NB2:Declaration of product_id in stock.move :
product_id = fields.Many2one(
'product.product', 'Product',
domain=[('type', 'in', ['product', 'consu'])], index=True, required=True,
states={'done': [('readonly', True)]})
My function :
changed = fields.Integer('Changed')
#api.onchange('changed')
def _changed_onchange(self):
move_lines = []
for line in self.move_lines:
move_lines.append({'product_id': line.product_id.id or False,
'product_qty': line.product_qty or 0,
'name': line.product_id.name,
'product_uom': line.product_uom.id,
'date_planned': datetime.date.today(),
'date_expected': datetime.date.today()
})
move_lines.append({'product_id': self.changed,
'name': 'default',
'product_uom': 1,
'date_planned': datetime.date.today(),
'date_expected': datetime.date.today()
})
return {'value': {'move_lines': move_lines}}
If i created the move lines using the view then saved, everything works fine but when i change the value of the field so that a new move line is inserted by the function, the save doesn't work and i keep getting the error:
Odoo Server Error - Validation Error
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set
[object with reference: product_id - product.id]
What is the problem ?
To append line to move_lines, You can use the following syntax:
#api.onchange('changed')
def _changed_onchange(self):
values = {'product_id': self.changed,
'name': 'default',
'product_uom': 1,
'date_planned': datetime.date.today(),
'date_expected': datetime.date.today(),
'location_id': 1,
'location_dest_id': 1
}
self.move_lines |= self.move_lines.create(values)
To achieve it using your above logic you can try x2many values filling but I recommend you to use Set operations and you can find an example at Lunching wizards

How to filter by sub-object in Rally 2 SDK

I'm trying to query for user stories whose release start date is greater than a particular date. Is it possible to do this using the "filters" config rather than querying all stories and then checking manually?
Is this valid? :
Ext.create('Rally.data.WsapiDataStore', {
model: 'UserStory',
context: {
project: '/project/xxxx'
},
autoLoad: true,
fetch: ['Rank', 'FormattedID', 'Release'],
filters: [
{
property: 'Release.ReleaseStartDate',
operator: '>',
value: '2012-10-10'
}
]
});
It doesn't work, just fetches all records.
The code posted above does work. I was actually using a comboBox value in the "value" property. Turns out I didn't convert it to a proper DateTime format and hence the comparison was failing and returning all records.
In my case I had to use Rally.util.DateTime.toIsoString in order to compare the value in the combobox.

Row Editor sending wrong Date

Recently I have upgrade my Ext version from 4.0.7 to 4.1.1
In my model I have defined like
{name : 'StartDate',type: 'date' ,dateFormat: 'time'},
My Grid Column is
{
id: 'StartDateID',
width: 180,
text: 'Start Date',
dataIndex: 'StartDate',
renderer : Ext.util.Format.dateRenderer('m/d/Y'),
editor:{
allowBlank: true,
xtype:'datefield',
format:'m/d/Y',
editable: true},
sortable: false, groupable: false }
On Edit I am doing
My_Grid.on('edit', function(editor, e) {
e.store.sync();
}
After clicking on Update I used to get [with Ext 4.0.7 ] date value as
2012-08-04T00:00:00
but after upgrade with 4.1.1 I am getting date value as
310008e
Which I am not understanding.
My date is in this format
1346351400000
Can you please suggest me what is missing here? Or else how to get proper date after clicking update button from RowEditor.
Your model definition is incorrect, if you want your desired format it should be like:
{name : 'StartDate',type: 'date' ,dateFormat: 'U'},
'time' is not in the documentation, the only reason you could actually be using 'time' is if it is a custom type you have created, which is probably not the case.

date format with extjs 4.1 issue

In my model (Ext.data.Model) i have the following property
{
mapping:'Created',
name:'Created',
type: 'date',
format:'d/m/Y'
},
On my form i have the following field
{
xtype:'datefield',
name:'Created',
fieldLabel:' Date',
format:'d/m/Y',
width: 350
},
If i select the following date in the picker "01/04/2012" ( i'm in the UK, 1st April 2012)
I get the following in firebug json post "2012-01-04T00:00:00" ( 4th Jan 2012 )
How can i ensure the correct regions are coming through
In your model you define Ext.data.Field.
Have a look in the API docs, Ext.data.Field has no configuration called format, but dateFormat.
Try this
{
name:'Created',
type: 'date',
dateFormat:'d/m/Y'
},
and you just need mapping, if your data from the backend has a different name as you want to use in the model.
BTW: since ExtJS 4.1.3 there also are two new config items: dateReadFormat and dateWriteFormat to define different format for the reader and the writer. But if you define dateFormat this will be the same for both.
on the form field you need the extra property submitFormat:
{
xtype:'datefield',
name:'Created',
fieldLabel:' Date',
format:'d/m/Y',
width: 350,
submitFormat: 'd/m/Y'
}