change event not getting triggered with poltergeist - backbone.js

I have 2 dropdowns and on change of first am prepopulating the second dropdown(which is been done in backbone).
events: ->
'change #client_id': 'selectedClientChange'
selectedClientChange: (ev) ->
#populateGroups $(ev.target.selectedOptions).val()
Written capybara specs for the same with poltergeist but change event is not getting triggered for some reason and spec is getting failed.
scenario 'it should populate the groups automatically', js: true, speed: :slow do
click_link 'New Item'
find('#name').set('Sample Item')
page.execute_script("$('#client_id').val('testing').trigger('change')")
select "#{client.name}", from: "client_id"
groups = find('#group_id').all('option').collect(&:text)
expect(groups.count).to eq 1
expect(groups).to include pg.name
end
Can someone tell me how to solve this.

Without details about the error you're getting this is mostly a guess - It's possible you're getting the groups before the change event from the select actually updates them. You'd be better off using the have_select matcher since it will retry for a time to see if the field changes to match the requirements
select "#{client.name}", from: "client_id"
expect(page).to have_select('group_id', options: [pg.name])

Ah sorry everyone. I see that there is an issue with poltergeist which I found here https://github.com/teampoltergeist/poltergeist/issues/204. Thanks alot!

Related

Getting issue with heremap multiple pickup and multiple drop api

I am using multiple pickup api with prams as suggested by heremap docs:
https://fleet.ls.hereapi.com/2/findpickups.json?mode=fastest;truck;traffic:disabled&start=waypoint0;50.115620,8.631210;pickup:GRAPEFRUIS,value:1000&departure=2020-11-14T07:30:00&driverCost=20&restTimes=disabled&end=waypoint7;50.132540,8.649280;drop:GRAPEFRUITS,value:1000&destination0=waypoint1;50.118578,8.636551;drop:APPLES,value:30&destination1=waypoint2;50.122540,8.631070;pickup:BANANAS&destination2=waypoint3;50.128920,8.629830;drop:BANANAS,value:30&destination3=waypoint4;50.118654,8.619956;pickup:APPLES&destination4=waypoint5;50.123998,8.640626;drop:PEACHES,value:50&destination5=waypoint6;50.130299,8.613031;pickup:PEACHES&apiKey={key}
drop for GRAPEFRUIT is defined but getting error message: No drop-off point defined for payload GRAPEFRUIS,value:1000
There are several issues with your url:
There is a typo (GRAPEFRUIS)
pickup doesn't have a value field (see https://developer.here.com/documentation/routing-waypoints/dev_guide/topics/api-reference-type-waypoint.html)
"pickup only allowed at optional way points"
So if you change
start=waypoint0;50.115620,8.631210;pickup:GRAPEFRUIS,value:1000
to
start=waypoint0;50.115620,8.631210
and
end=waypoint7;50.132540,8.649280;drop:GRAPEFRUITS,value:1000
to
end=waypoint7;50.132540,8.649280
then this url will work:
https://fleet.ls.hereapi.com/2/findpickups.json?mode=fastest;truck;traffic:disabled&start=waypoint0;50.115620,8.631210&departure=2020-11-14T07:30:00&driverCost=20&restTimes=disabled&end=waypoint7;50.132540,8.649280&destination0=waypoint1;50.118578,8.636551;drop:APPLES,value:30&destination1=waypoint2;50.122540,8.631070;pickup:BANANAS&destination2=waypoint3;50.128920,8.629830;drop:BANANAS,value:30&destination3=waypoint4;50.118654,8.619956;pickup:APPLES&destination4=waypoint5;50.123998,8.640626;drop:PEACHES,value:50&destination5=waypoint6;50.130299,8.613031;pickup:PEACHES&apiKey={key}

Jovo FrameWork: this.followUpState doesn't do its job like it's supposed to

I have this intent
'NameIntent': function(name) {
let speech = 'Hello ' + name.value + ', nice to meet you! which Radio do you want me to play? ;
this.followUpState('MakeSureEnterRadioIntentState').ask(speech);
},
which gets triggered with the utterance {name}. Example: User says: SAM
The stateIntent code is as follows:
The PlayRadioIntent get triggered with the utterance {radioName}. Example: User says: Mosaique
'MakeSureEnterRadioIntentState': { //TO solve this problem: IN CASE USER SAYS MOSAIQUE AFTER NAMEINTENT ALEXA WILL INTERPRET MOSAIQUE AS A NAME AND WILL REENTER NAMEINTENT
'PlayRadioIntent': function(channel) {
this.tell("The radioName is" + channel.value);}
The problem I tried to resolve with this state:
ALEXA: Hello Sam nice to meet you! which Radio do you want me to play? ;
USER: Mosaique
//Mosaique is a radio name
ALEXA: Hello Mosaique nice to meet you! which Radio do you want me to play? ;
//ALEXA interprets mosaique as a name instead of a radioName and reenters the NameIntent. I thought using states would be perfect for resolving this confusion. and they SHOULD. But, they aren't and I do not really understand why.
HELP?
The Jovo Routing works as follows if it is in a state: (1) Look if the intent is found in the state, if not (2) look if "Unhandled" is defined in the state, if not (3) look if the intent can be found outside the state, if not (4) look if "Unhandled" is defined outside the state, if not (5) throw an error.
In your case, "NameIntent" can't be found in the state, so it goes to the global (stateless) "NameIntent". To stay in the state, you can add an "Unhandled" intent that acts as a "catch all" for any intent that can't be found in there.
Take a look at this section to learn more about states and Unhandled: https://www.jovo.tech/blog/p2s5-introduction-to-states/#unhandled-intent

Angular advanced searchbox lose focus after selecting suggested key-value per keyboard

I've implemented the angular-advanced-searchbox (with AngularJS 1.5.8, ui-bootstrap, JQuery) like the demo-page:
html
<nit-advanced-searchbox ng-model="searchParams" parameters="availableSearchParams" placeholder="Search..."></nit-advanced-searchbox>
script
$scope.availableSearchParams = [
{...},
{
key: "city",
name: "City",
placeholder: "City...",
restrictToSuggestedValues: true,
suggestedValues: ['Berlin', 'London', 'Paris'] },
{...}
];
};
Here is a Plunker of this implementation too. I'll refer to this example to picture my problem.
If I type 'city' in the searchfield and select it by hitting enter, then I'll see the suggested Value-List (Berlin, London, Paris) for about a second and then the focus 'll lost and the selected key-value (city) is automatically removed. It seems this won't happen, if the mouse pointer is rested over the search-input field (without any action).
With this issue, I can't use this module on my site - but I really want to :) Are any suggestions out there?
OK, this (low-level) fix worked for me - i've just commented line 107 ():
angular-advanced-searchbox-tpls.js [#107]
$scope.searchQueryChanged = function (query) {
// updateModel('change', 'query', 0, query);
};
This line is used to build 'pre-queries'. If you start typing 'city', the scope of searchParams generate a temporary query on the fly and would be changed to the selected key - g.E.:
{"query":"ci"}
This will then lead to a timeout after 'city' is selected. I don't know this 'query' is used for - all things 'll do their job furthermore. But by time I'll looking to a real fix for this problem :)

Extjs 4.0.7, Editor Grid - how to get updated cell value?

I need to get(retrieve) updated cell value in controller. (MVC)
So I tried this,
var modified = this.getItemGrid().getStore().getUpdatedRecords();
console.log(modified); // return [] empty array
var modified = this.getItemList_Store().getUpdatedRecords();
console.log(modified); // return [] empty array
but always it returns empty array even I updated some cell value.
anybody know what I am doing wrong?
Here is my part of view code,
Ext.define("App.view.orders.ItemList_view", {
extend: "Ext.grid.Panel",
alias: "widget.itemList_view",
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
initComponent: function () {
this.store = "ItemList_store";
this.columns = [
{
xtype: 'checkcolumn', text: "Ship", width: 50, dataIndex: "DR"
},
{ header: "test", width: 100, dataIndex: "test",
editor: {
xtype : 'textfield'
}
}
];
this.selModel = Ext.create("Ext.selection.CheckboxModel");
//this.selModel = Ext.create("Ext.selection.CellModel"); // It does not works either.
this.callParent(arguments);
},
.
.
.
Thank you!
[EDIT]
Thank you very much for your answer! I have some more question about editor grid.
Its much different from Ext3. so I'm very confusing now :(
Q1. How to collect edited record data (once click button)?
the event fired once the grid cell be changed.
but I want collect edited grid record once I click the 'Update edited cell' button, and I want to update all together at the once.
In Ext3, I did like this,
(button) click : function(){
var modified = mygridStore.getModifiedRecords();
var recordsToSend = [];
Ext.each(modified, function(record){
recordsToSend.push(record.data);
});
var grid = Ext.getCmp('grid');
grid.el.mask('Updating','x-mask-loading');
grid.stopEditing();
recordsToSend = Ext.encode(recordsToSend);
Ext.Ajax.request({
url : '/test/test',
params : {
data : recordsToSend
},
success : function(response){
grid.el.unmask();
alert(response.responseText);
mygridStore.commitChanges();
},
failure : function(response){
mygridStore.rejectChanges();
}
});
}
How can I change the code for Extjs4 ?
Q2. I don't know still how to find out for changed checkcolumn.
I tried this, but I does not work for checkcolumn (of cause I tested after change checkbox)
// grid coumn
{
xtype: 'checkcolumn', header: "My Check Column", width: 50, dataIndex: "CH"
}
-
// in control
'myGrid': {
validateedit: function (plugin, edit) {
console.log(edit);
},
checkchange: function (plugin, edit) {
console.log(edit);
console.log(edit.value);
}
}
Q3. When I click the cell to edit, the show some HTML tag in -_-;;
I really appreciate for your help. and thank you very much for your valuable time!
The editors (cell editors or row editors) do not commit their values to the store until you complete the edit - which means pressing ENTER or blurring the active cell editor by clicking elsewhere on the page, or clicking the save button on the row editor form .
If your purpose for reading the updated value in your editor is to perform some kind of validation I would suggest simply listening to the validateedit event in your grid's controller, as described here.
The second argument that this event passes to your handler contains a lot of data about the edit that you can then perform validation with. If the edit doesn't pass your validation you can return false from your handler and the value in the celleditor will revert to it's original value. The validateedit event gets fired from the editor grid itself so you would add an event handler in your controller for it like this:
Ext.define('MyApp.controller.MyController', {
init: function() {
this.control({
'mygridpanel': {
validateedit: function(plugin, edit) {
// silly validation function
if (edit.value != 'A Valid Value') {
return false;
}
},
},
});
},
});
But you should check out the link above to see all the different objects available in that second argument I named edit.
The validateedit event is fired right before the record is committed into the store - after the user has already clicked ENTER or blurred the editor, i.e., while the editor is closing.
If you are trying to get the celleditor's value before it starts to close, for some reason other than validation for example, you could get the active celleditor's value like this:
// myGrid is a reference to your Ext.grid.Panel instance
if (myGrid.editingPlugin.editing) {
var value = myGrid.editingPlugin.getActiveEditor().field.value
console.log('value: ' + value);
}
If there is no active editor then myGrid.editingPlugin.getActiveEditor().field would throw an error, that's why I wrapped a conditional around it.
One other point I should make, for validation in editor grids, I found that it is easiest to just put a validator config in the grid column's editor definition. That will give you all the handy validation CSS while the user is setting the field's value and alert him if there is a problem with the value before he tries to save it.
To get an idea of what I mean, try entering letters in the date column of this example. Mouse over the editor cell and you will get the error message.
EDIT
It seems I misunderstood you original question, I'll break down my answers to your questions above though,
Question 1
Once you have completed an edit (clicked ENTER or ), your call to mygridStore.getModifiedRecords() should be working fine because the record will have been committed to the store. I see that it was not working, I will cover that in a moment.
I should point out that ExtJS4 has a store.sync() method as covered here.
Instead of extracting the modified records from the store, encoding them, manually doing an ajax request to save them to the server and then manually committing them you can call this sync method and it will take care of all of these actions for you.
If you have different URLs to handle the different create, read, update, destroy operations fired off by your store's load and sync methods, you can use the store's proxy api config to map your URLs to these operations as covered here. Or you can set-up your server side controller to be able to differentiate between your store's load request (read operations default to HTTP GET) and it's sync requests (create, update and delete operations default as HTTP POST).
There could be many different ways to go about doing this on the server side, the way I usually do it is to have one SQL stored procedure for GET requests and one for POST requests for any given store. I include the store name as an extra param and then my server side controller runs the appropriate stored procedure based on whether it is a GET or a POST request.
Question 2
Cell editing doesn't support checkcolumn edits. You have to make a different handler to listen to changes on that, something like this:
checkchange: function (column, rowIndex, checked) {
var record = store.getAt(rowIndex),
state = checked ? 'checked' : 'unchecked'
console.log('The record:');
console.log(record)
console.log('Column: ' + column.dataIndex);
console.log('was just ' + state)
}
Your call to mygridStore.getModifiedRecords() should be able to pick up the check changes also however, they get committed to the grid's store right away after being checked. store.sync() would also pick up changes to checkcolumn.
Question 3
I can't completely tell what is causing that problem but it may be something strange going on with your validateedit event, your handler should be returning true or false.
As I said earlier, I misunderstood the reason you originally asked this question. I thought you were trying to do some kind of validation while an edit was in progress. Now I understand that you are trying to get all of the modified records from the store after all the editing is completed in order to save them to the database, I was thrown off because in ExtJS 4 a store is usually saved to the database with the sync method as I mentioned.
In other words, you don't need the validateedit event or checkchange event to get a list of modified records.
The actual problem you are having might be trouble with the store's getter methods (getModifiedRecords, getUpdatedRecords) in some 4.07 versions, take a look at this post and this one.
So with all that said, the best advice I can give you is 1) try out the stores sync method for saving modified data to the database and 2) upgrade to ExtJS 4.1, there were a lot of bugs that were straightened out between 4.07 and 4.1 which you should be able to take advantage of, I cut out about 75% of the overrides I was using to make things work when I switched over to 4.1.
EditedGrid.plugins[0].completeEdit();
This will make the active changes commit and call edit event also.
listeners: {
validateedit: function (editor, e) {
//console.log(editor);
var oldVal = editor.originalValue;
var newVal = editor.value;
}
}

Mongoid criteria for id

I before the current Mongoid version 2.0.2, I was able to do
User.criteria.id( 1234 ) #=> user#1234
But now it throws a no method error. Has this been changed to something else or has it been removed?
Thank you for your input
You could always do this:
User.where(:conditions => {:id => '1234'})
Or if you didn't actually need a criteria object (and just wanted the user with id '1234') you could just do:
User.find('1234')
Found it, they (mongoid team) did remove the criteria#id selector from the latest version of mongoid. The reason why I don't use Model.find is because it doesn't do lazy loading, where criteria#id does. But back to the issue here. They replaced criteria#id with criteria#for_ids
So Model.criteria.for_ids('1234') will work

Resources