Search code examples
dynamics-crm-2011dynamics-crm

Dynamics CRM mandatory field which appears twice on the form, once hidden once visible


I have a form which has two sections, both of which contain a particular field that is "business required". In my current scenario the first of these sections is hidden, while the second is visible. (Basically, which of the two is visible is set in JScript and depends on the value of a drop down list).

The problem is that if the user does not enter a value for the mandatory field and then hits save, the form attempts to validate it on the first of the two occurrences, (i.e. the one that is not visible). When it discovers that the user has not filled this value, it then brings the hidden section into view despite the fact that the same offending field is already in view further down the form.

Is there any way I can stop it doing this, or workaround my issue in another way?

Edit:

OK, from the answers below, I think maybe I didn't make the situation clear enough. I don't think setting the field to be non-mandatory, or filling it with a token value, will do the trick because I do want the mandatory status to be validated if the user has not filled in the field.

The issue I'm having is that having validated it, it is showing the user the version of the field that had been hidden, rather than the one that is already visible.

Image depicting the scenario. When the form is validated, the hidden section (shown with red border) appears, because the "Consultant" field is not filled

As far as I know the simple API, to set the field to mandatory or not, applies equally to any occurrences of that field on the form, not one specific one.


Solution

  • Edit: ok this isn't pretty but should work.

    You can get at the collection of values using

    var bothControls = Xrm.Page.getAttribute('transactioncurrencyid').controls
    

    And using

    bothControls.get(1)
    

    Gives you the second (zero based index, natch) so you can make it disabled

    bothControls.get(1).setDisabled(true)
    

    Which means validation will be skipped