使用 jQuery 检索表单值
可悲的是,这并不像我希望的那样简单。在过去的几周里,我一直在研究 jQuery 在 CRM 中的使用。虽然它对于样式改变来说很好而且很花哨,但我找不到任何更接近业务逻辑的示例。
例如,今天如果 4 个字段之一为空,我需要提醒浏览器。两个是日期字段,一个是选项列表,一个是复选框(位)。我认为调用 $("#formElement").val() 会获得该值,在某些情况下确实如此,例如我将其解析为 int 后的选项列表。但是,日期字段始终返回空字符串。
查看 CRM 表单 HTML,我发现“#formElement”并不总是 CRM 表单元素的输入 ID。举个例子,日期字段的 ID =“DateTime”(或类似的内容)。此时,我原以为我需要创建一个过滤器,它将采用包含 #formElement 作为 ID 的表,并查找该表中第一个输入的值,但此时使用 crmForm.all.formElement .DataValue 看起来更容易。
我确信这里有人对此有解决方案(也许还有一些有关如何编写 CRM 表单来帮助过滤器的解释),而且在工作中无法安装 Internet Explorer 的附加组件确实很糟糕。感谢您的任何和所有帮助。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 jQuery 选择表单本身(通过其 ID 或仅通过 $(form)),然后迭代其 子项 是输入文本字段。我以前没有在表单中这样做过,但它可能对你有用。
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.
对于其他正在寻找答案的人来说,我已经在可控的程度上找到了答案。不幸的是,我无法使用 CSS 选择器来缩短属性名称,但我已经能够利用 jQuery 来缩短时间。如果您想将 CRM 4 属性与 jQuery 一起使用,它看起来像这样:
我真正想要的是链接,因为很多时候我需要清空一个字段,禁用它,然后强制它提交。一点点魔法,这:
变成:
我希望这可以帮助你们中的一些人!
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:
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:
Becomes:
I hope this helps some of you guys out!