开发者

Retrieving form value with jQuery

开发者 https://www.devze.com 2023-04-07 20:50 出处:网络
Sadly, this isn\'t as cut and dry as I had hoped. Over the past few weeks I had been researching the use of jQuery with CRM. While it\'s nice and dandy for style alterations, I couldn\'t find any exam

Sadly, this isn't as cut and dry as I had hoped. Over the past few weeks I had been researching the use of jQuery with CRM. While it's nice and dandy for style alterations, I couldn't find any examples that are closer to business logic.

For example, today I needed to alert the browser if one of 4 fields were empty. Two were date fields, one a picklist and one a checkbox (bit). I thought that calling $("#formElement").val() would have gotten the value, and in some cases it did, such as the picklist after I parsed it as an int. However, the date fields always returned an empty string.

Looking through the CRM form HTML, I see that "#formElement" isn't always the ID of an input for a CRM form element. Case 开发者_Python百科in point, the date fields had ID="DateTime" (or something similar). At this point, I had thought that I will need to create a filter that will take the table that contains #formElement as it's ID and look for the value of the first input in that table, but at that point using crmForm.all.formElement.DataValue just seemed easier.

I'm sure someone here has a solution for this (and maybe some explaination of how CRM Forms are written to help with a filter), and it really stinks not being able to install add-ons for Internet Explorer here at work. Thanks for any and all help.


Use jQuery to select the form itself (either by its ID or just by $(form)) and then iterate over its children that are input text fields. I haven't done this for a form before but it might work for you.


For anyone else who is looking for an answer, I have figured it out to a managable degree. Unfortuantely, I haven't been able to use CSS selectors to shorten attribute names, but I have been able to utilize jQuery to cut down on time. If you'd like to use a CRM 4 attribute with jQuery, it looks like this:

$(crmForm.all.new_attribute).bind("click", function() { ClickFunction(); });

What I was really gunning for was chaining, because there are plenty of times when I need to null a field, disable it, and then force it to submit. A little bit of magic and this:

crmForm.all.new_attribute.DataValue = null;
crmForm.all.new_attribute.Disable = true;
crmForm.all.new_attribute.ForceSubmit = true;

Becomes:

crmForm.all.new_attribute.dataValue().disable().forceSubmit();

I hope this helps some of you guys out!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号