g.nodeName is undefined - javascript

I'm converting a login/registration page to using Ajax/jQuery. As such, there is alot of common validation functionality between the two forms. One area that I'm using jQuery for is to output error messages to the user based on the input. While the forms share similar element IDs, class names differ.
So for checking the username, I have
if ($(":input").is('.registerName')){
//Username belongs to the registration form, so check if current entry is
//valid and not taken. Output error message otherwise
} else {
//username belongs to the login form, so check if current entry exists in database
//output username/password error depending on catch
}
I've experienced some strange happenings.
First, the above code returns a g.nodeName is undefined error. If I change the initial conditional to
if ($("input#username").is('.registerName'))
the same error shows up in Firebug.
However,
if ($("#username").is('.registerName'))
and
if ($("#username").hasClass('registerName))
both fail and the login validation section executes.
So how can I get the right code block to execute based on class name without a g.nodeName undefined error?
EDIT
To clarify- there are NOT two forms on the same page. The code functionality is in the javascript. I'm referring to two separate HTML forms on differing pages that call the same JS function and the only difference is the text in the error messages output.
EDIT 2
JFiddle example: Here
The text box onclear doesn't work for the fiddle, but I think you can get the gist of what I'm trying to do.

I can't reproduce the exact issue you got, but try
if ($(this).is('.registerName'))
instead. That way you'll know it's only looking at the particular element on which the keyup event occurred. $(':input') will look for all inputs on the page.

Related

Dynamic form component markAsDirty() Error: ExpressionChangedAfterItHasBeenCheckedError

I have an app with a dynamic forms component which is something like this stackblitz:
https://stackblitz.com/edit/angular-g3a7cm?file=src%2Fapp%2Fform.component.ts&devtoolsheight=50
The form.component loads a schema and some data from the server. If data was loaded for a particular field it marks it as dirty by calling markAsDirty(). This is so if dirty autosaved data is loaded proper validation messages can be displayed immediately.
There is also a form-field.component which has a function that evaluates a disabled condition and disables/enables the field.
I'm getting the error the first time any field on the form is disabled.
If I comment out either of these lines the error goes away:
form.component.ts:50
form-field.component.ts:42
Anybody have any good idea why this is happening and how I might fix it?
I have looked at other similar questions but none seem to be the same as my specific issue.
Thanks for looking.
edit:
Also, if I put the initial call to evalDisabled() in a setTimeout it fixes it. (form-field.component.ts:32) I thought the point of reactive forms was that they were supposed to allow synchronous logic. Why should I have to do this?

How can I use Javascript to check my checkboxes without causing an event validation error?

I have a grid view with check boxes in a template field that are used to delete one or more rows at a time. I then have a button that posts back to the server and deletes any row with a checked checkbox. That works fine. I recently added a button that automatically deletes all the rows by checking every box with JavaScript and then posting back and running the same function to delete rows that are checked. This also works, but then after that (using my 'Delete All Button'), any other post back causes an event validation error, which I presume is caused by using JavaScript to check all my boxes.
Error:
Unhandled exception at line 885, column 13 in
PageOmitted
0x800a139e - JavaScript runtime error:
Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback
or callback argument. Event validation is enabled using in configuration or <%# Page
EnableEventValidation="true" %> in a page. For security purposes,
this feature verifies that arguments to postback or callback events
originate from the server control that originally rendered them. If
the data is valid and expected, use the
ClientScriptManager.RegisterForEventValidation method in order to
register the postback or callback data for validation.
First off, it's strange to me that the error pops up on the next post back, rather than the one causing the issue. But my question is what can I do to get past the event validation? Is there an easy way to do that? I looked at the 'RegisterForEventValidation' method mentioned in the error on MSDN, but I couldn't make heads or tails of that...any options?

How to suppress a text field in JavaScript?

I am working on a business cards project with variable data printing done online. I need a rule I can use so that the fields that are not used or left blank will be suppressed.
At the moment I am getting a blank test field between two text fields if it is left blank. I am new to this so any help will be appreciated.
I'm assuming your situation involves a user typing data into an HTML form after which the information is displayed somehow on an HTML page. If any of that is false, we will need more information to answer your question. It sounds like you have already figured out how to send the information from form to display and you just want to not see empty lines of display. That is handled with CSS style.
First, you need to have some way to test whether the field contains user input. Since you didn't offer any code to build on, I'm going to assume for the moment that you can figure out how to do that.
Then you can use JavaScript to programmatically alter the CSS of a given element. It will go something like this:
if (field_modified === false) {
// cause an HTML element to not be displayed
// here, the value associated to whatever field
// you are testing is displayed in an HTML node with ID 'id_of_node_here'
// There are various other ways of accessing specific HTML nodes
// without giving them IDs. You can research that yourself.
document.getElementById('id_of_node_here').style.display = "none";
}
To test user input in a field, it's probably sufficient to test the length of the value or whether a form element has been changed from default.

Crm field control order Javascript

I would like to change the order in which the fields in a form get checked.
The field Email should be checked before the field City. They are both obligatory.
I would also like that when the email address is invalid only one Popup is shown (by default I get two- one saying the email is invalid and one saying that the field cannot be null)
Is it possible to change the order of the checks and do the custom checks before the system ones?
Marco
The only supported method of changing the order in which the fields get checked, is changing the order on the form. I'm assuming that CRM just loops through it's collection of controls to perform the field validations. You could attempt to dive into the CRM javascript and figure out a method to hijack it.
A supported way of handling it would be to make the fields not required (either via javascript on the OnLoad, or updating the entity definition itself), and then on the OnSave, writing your own field validation. It's a lot of extra work, and you lose the little red asterisk showing the field is required, but you'd be able to evaluate them in the order you'd like (or display a single message with everything that's missing (why that isn't done by default in CRM I'll never know)), and be able to fix your email invalid / not null message.
CRM does not loop through its collection of controls as specified in the answer above.
The validation of the fields(business required) on a CRM form happen in the order in which they were added to the form, irrespective of where they are placed in the form. So, as of now, the only way to change the order in which they are validated is to add them in the same order as you want them validated.
So far.. I believe the only option to work around this is stated in this link.
http://social.microsoft.com/Forums/en-US/8f402463-23aa-4bc1-862b-4f4093a0cce8/required-fields-order-of-validation?forum=crmdevelopment
Basically you would need to use javascript. Have only one field as mandatory. On change of this field set the next field (in the correct order) to mandatory and so on.. hectic but only way.

Call a JavaScript method after the RequiredFieldValidator fires?

Is it possible to fire a JavaScript method after a form element is considered invalid? Here is my scenario:
There are 2 tabs on the ASPX page. The user has to fill out info on both tabs. The user, while on tab 2 clicks the submit button. However, there is a required field on tab one that needs attention. Do I need to create a custom valuator (either a CustomValidator control or create a new control from the base valuator) to call a JavaScript function to display tab 1 and show where the error is?
Unfortunately, the canned Field Validator controls in ASP.NET Webforms are not very extensible. I've had needs to change the CSS class of an input field to an invalid state upon client-side validation, and I never found a good way to handle this.
I think your best bet might be to do your own client-side validation. I've also looked into this third party product and it seemed to be pretty fully-functional, but I couldn't justify the cost in my case: http://www.peterblum.com/DES/Home.aspx
You can call any js function from your server side code after the validation check on page object and inside the js function you can write the logic to highlight the field which has issue on validation:
if(!Page.IsValid)
{
Page.ClientScript.RegisterStartupScript(typeof(Page), "validate", "myjsfunction();", true);
}
else
{
// type code here
}

Categories