Answered by:
CRM2011: Hidden required field issue

Question
-
Consider the following scenario
Form1
Tab 1
Field A
Tab 2
Field B (required)
Tab 3
Field B (required)
Based on the selection of Field A, Tab 2 or Tab 3 will be hidden.
The issue here is when Tab 2 is hidden and Field B has not been filled out yet, when saving the form, the required validation will kick in and it will set the focus on the first instance of the attribute (which is the Field B in Tab 2). As the result, it makes the hidden Tab 2 to be unhidden.
Is there any quick way to set the focus on Field B in Tab 3 instead, without additional codes in onSave event?
Thanks- Edited by HanVo Tuesday, January 3, 2012 10:23 PM
Tuesday, January 3, 2012 10:19 PM
Answers
-
Yes. it's what I meant.
Disabling the first instance (control) of the attribute does work
Xrm.Page.ui.controls.get('field_b').setDisabled(true)
Thanks.
- Marked as answer by HanVo Wednesday, January 4, 2012 10:21 PM
Wednesday, January 4, 2012 10:21 PM
All replies
-
Hi,
As I understand the issue,
You want to hide/show Tab 2 and Tab 3 based on the selection of Field A (on Tab 1).
One way of doing that would be to simply do that by doing the following
- if a user selects an option (assuming Field A is an option set) and based on that you want to hide Tab 2 then use this code to set the requirement level of Field B (of Tab 2) to none. which means that you are setting it to "No Constraint" from being "Required"
Xrm.Page.getAttribute("field_b_of_tab2").setRequiredLevel("none");
after this line of code, then hide Tab 2 then it will not be unhidden because we have already taken out the constraint from the field B of Tab 2.do the same for Field B of Tab 3 if you want to hide Tab 3 based on selection.
You can also set it back to "Required" by using the following line of code based on your business logic.
Xrm.Page.getAttribute("field_b_of_tab2").setRequiredLevel("required");
Let me know if you need more information,hope it helps
cheers, S.Khan MCTS- Proposed as answer by Sanaullah Khan Tuesday, January 3, 2012 10:52 PM
Tuesday, January 3, 2012 10:51 PM -
This code
Xrm.Page.getAttribute("field_b_of_tab2").setRequiredLevel("none");
will also set Field B in Tab 3 Not Required because they are the same instances.
I think one way to get around this is to loop through the controls of the attribute and disable the one that are in the hidden tab. I will post back if this does work.
Thanks.
Wednesday, January 4, 2012 2:42 PM -
oh ... by same instances you mean adding the same field twice on different tabs..
yes you will be able to disable it that way. through html source
cheers, S.Khan MCTSWednesday, January 4, 2012 9:38 PM -
Yes. it's what I meant.
Disabling the first instance (control) of the attribute does work
Xrm.Page.ui.controls.get('field_b').setDisabled(true)
Thanks.
- Marked as answer by HanVo Wednesday, January 4, 2012 10:21 PM
Wednesday, January 4, 2012 10:21 PM