testing angularjs application using casperjs - javascript

When testing an Angular application using Casper I found that the binding between inputs and model didn’t seem to be happening when I filled in form fields. I used Casper’s fill method but found that the Angular form validation was rejecting any required fields as though they were still blank.
Name
Email
Subject
Message

I'm looking around to do something similar, but slightly different (my problem as yet unsolved). However while looking I came across the following article that would appear to be what you want.
http://blog.freeside.co/post/41774715101/testing-angular-forms-with-casper
Basically the fill method in casper doesn't trigger Angular's input event, so Angular doesn't do its thing and you end up with blank post data. The blog entry shows how to override the fill method with coffeescript so the event gets fired.
Hope this helps.

Related

Use client-side script to set Business Process Flow Stage on Opportunity in Dynamics CRM

I'm working in Dynamics CRM 2015 Online and need to apply some conditional rule to the Opportunity when it is first created from a Lead qualification. Under certain conditions we need to automatically advance the Business Process Flow stage to the second stage in the flow. I've already tried this using variations of a plugin on Opportunity Create to set the stage id, but it seems that any value I assign there is ignored when the Opportunity is created from a Lead. Right now I'm trying to fire a javascript function during the Opportunity Form OnLoad event. One catch here is I'm also working against a field that is business required but not filled in when the Opportunity is created from a Lead so I can't do a simple Xrm.Page.data.process.moveNext() in the script. Instead I am updating the Opportunity using the JQuery SDK function updateRecord that is part of the CRM SDK scripts. Here's the important bits of the code:
opp = {
OpportunityId: oppId,
StageId: newProcessStageId
}
SDK.JQuery.updateRecord(
oppId,
opp,
"Opportunity",
function () {
// success, refresh the form
Xrm.Page.data.refresh();
},
function (error) {
alert("An error occurred while updating the opportunity: " + error.description);
}
);
This does work to change the stage, however the problem is on the form the Business Process Flow still shows the first stage as the selected stage, even though it moved the flag indicating the active stage is stage 2, as seen in this screenshot:
After the update, I do a refresh of the form data, but I don't see any way to set the "selected" stage to match the new active stage. I've scoured the SDK docs and searched around but can't find anything that will do this. Any help is much appreciated!
Unrequire the the required field on load in order to change the stage. Then try to move to the next stage.
What if you do a Xrm.Utility.openEntityForm() call instead of a data.refresh? (BTW, I've been trying to find a way to set selected stage in JS for a while as well, and haven't found anything either. I do think if you completely reload the form instead of just the data, though, it should set the selected to the active.)

semantic ui remote validation

I am using Semantic UI along with ASP.NET MVC. I have performed client-side validation in my registration form as described in the documentation http://semantic-ui.com/modules/form.html Now i want to validate an email in order to be unique. So i have to make an ajax request to the server (this is something i know how to do). But how can i add such a rule in Semantic UI and display a corresponding error message?
After a little search at the docs I found the behavior add errors. It works like
$('.your.ui.form').form('add errors', ['Your error string 1', 'Maybe another one?']);
However, this will only change the text in the error messages. If the error message is not displayed at that time, you will probably want to show it. Add the class 'error' to the form:
$('.your.ui.form').addClass('error');
And of course you can chain these two methods like
$('.ui.form')
.form('add errors', ['oh my error'])
.addClass('error');
Here's a fiddle

Attempted to handle event `willCommit` on while in state root.loaded.updated.inFlight

I'm learning how to use EmberJS by doing the introductory tutorial form the "Getting started" page. However, when I get to the "Accepting edits" part, I have a bug:
Uncaught Error: Attempted to handle event `willCommit` on <Todos.Todo:ember304:3> while in state root.loaded.updated.inFlight.
The call to Todos.TodoController.acceptChanges() seems to be triggering that error. The part I'm referring about is this one:
http://emberjs.com/guides/getting-started/accepting-edits/
After reading up on model lifecycle in Ember - http://emberjs.com/guides/models/model-lifecycle/#toc_in-flight - I still don't get why this bug appears.
One work-around is to save the model each time it changes (so every time the value of the <input> changes. Which works fine but would probably perform poorly with a HTTP API (as opposed to fixtures).
Could this be due to BC breaking changes in the ember-data lib?
What else could cause this?
Versions of libraries I've used:
jQuery: 2.0.3
Handlebars 1.0.0
EmberJS: 1.0.0 RC7
Ember Data: v0.13-102-g6bdebe7
After reading up on model lifecycle in Ember - http://emberjs.com/guides/models/model-lifecycle/#toc_in-flight - I still don't get why this bug appears.
This is not a bug, the in-flight section say's it all:
A record that is in-flight is a dirty record that has been given to the adapter to save the changes made locally. Once the server has acknowledged that the changes have been saved successfully, the record will become clean.
This means that you are trying to change the record while a previously change made it dirty and a possibly call to this.get('store').save() is still in the doings e.g. waiting for the server to respond. During this time frame you can't make changes to that same record without getting the error.
So a solution could be to not trigger this.get('store').save() after a character of the textbox has changed but rather on focus out for example, or even with a explicit button to save the record which you could disable until your server acknowledges it's change, this would not make a request for every character to the server resulting in sluggish performance due to some latency. Hope this makes sense.
Hope it helps.
I had this same issue with the Getting Started guide. I solved it by checking if the model was currently saving in acceptChanges:
acceptChanges: function() {
var model = this.get('model')
if (model.get('isSaving')) { return }
this.set('isEditing', false)
model.save()
}

flowplayer html validation

Ok, Im trying to rebuild a clients website thats long over due for cleanup on the backend and under the hood. This client uses flowplayer for most of the videos seen on any of there sites, and while attempting to validate my code via w3c validator I notice that the validator is throwing 2 errors both pertaining to flowplayer in this case.
http://validator.w3.org/check?uri=http%3A%2F%2Fv2.newyorkbarshow.com%2Fhome&charset=%28detect+automatically%29&doctype=Inline&group=0&user-agent=W3C_Validator%2F1.3
I am using the latest flowplayer out, and following there example (which I don't know if that validates either). So I am wondering if it doesn't validate out of the box, if anyone happens to know a means of correcting it so it will validate.
You need to add data attribute with value "/static/imgs/static/VidAd4BarShow.swf" in your object tag.
note : I see this happens before flow player executes anything within your source...

jQuery plugin: Validation can't be customized without setting all fields to 'required'?

I've spent the day looking at jQuery plugin: Validation by Jörn Zaefferer. I notice that it works fine as long as you call the validate() method without options. In my little squalid world, as soon as I add options, like errorPlacement, I notice that validation ignores form fields that are not marked required. I also notice that many, many demos mark all fields required---or do not pass options. Am I writing about anything familiar here? Or should I astral project to a parallel universe?
Note: This is to close the question out and provide info to resolve this to the next person finding the question since the OP has resolve the issue.
If there are any errors in the options, it will act the same as ignoring the fields, this isn't the validation plugin behavior per se, but rather how javascript works overall...any errors and it blows up (in mosts cases).
Double check all your options and use either Chrome's tools or FireBug to see if there are any script errors at all. Judging from your question, this seems the most likely culprit, fixing any errors in your options/errorPlacement will eliminate the onstacle in making the validation plugin work.
Also for testing, it's very helpful to use the debug option on the validation plugin, like this:
$("form").validate({
//other options
debug: true
});
This prevents the form from actually submitting, allowing you to tweak the validation much faster.

Categories