marceljd
marceljd
Offline
0
I have two single selection fields. One is dependent on the other. Both are required fields. I have a Javascript which hides a third field based on the value of the dependent field. In situations where there is only one possible value in the dependent field, I default to that value instead of leaving it at ‘(none)’ which would require the user to select the only possible value. I think that is a friendly and intuitive way to do it.

The problem is that the dependent field set this way doesn’t trigger the OnChangeCallback. Putting a callback on the independent field also doesn’t work because the javascript runs before the dependent field value changes.

How do you deal with this situation? I’d rather not have to leave the value at ‘(none)’ and force the user to select the one and only possible value.
Responses (4)
  • Accepted Answer

    Derek
    Derek
    Offline
    Tuesday, January 03 2012, 08:15 AM - #Permalink
    0
    Did you get anywhere with this? i'm running into the same issue.
    The reply is currently minimized Show
  • Accepted Answer

    Jeff Malin
    Jeff Malin
    Offline
    Friday, January 06 2012, 06:29 AM - #Permalink
    0
    I think I posted on this a while back but can't seem to find it, basically you need to have the change callback on the first field spawn a custom event listener (use setInterval/clearInterval to build one) which wait until the value of the second field is set by SBM after it gets the dependent values. You can watch the field directly, or listen for the value of parent.madeRequest, which is set to 1 but will will go back to 0 when the callback is finished.

    I think I already put an enhancement request out there for the SBM JS API to make AddChangeCallback work right on dependent fields, by looking into their driving field and making an additional hook into its callback that's triggered when the APFRequest (SBM's version of an AJAX callback) completes. This works around the issue, as you've found, that change events in browsers fire when a change is made by the user directly on an object, but not when the object is changed by a script.
    The reply is currently minimized Show
  • Accepted Answer

    Derek
    Derek
    Offline
    Monday, January 09 2012, 05:44 AM - #Permalink
    0
    Thank you, this is the response i received from Serena but it doesn't seem to work...at least not with relational fields. By chance, do you have any examples of your code? And was it with relational fields or something else?

    From SERENA:

    It sounds as though there are two solutions available. Here are some example scripts from a related case.

    You can manually set the FireChangeEvent:

    _____________________________________________

    SetFieldValue("GPM_UNIT", "PCCM","true");

    var gpmField = GetFieldByName("GPM_UNIT");

    FireChangeEvent(gpmField);

    _____________________________________________

    Or, in the javascript, it appears that the firechange event is fired by the true statement, but not if the true is in quotes, like "true" :

    _____________________________________________

    SetFieldValue("GPM_UNIT", "PCCM", false);

    which will not automatically attach the onchange event or to:

    SetFieldValue("GPM_UNIT", "PCCM", true);

    and then you will not need to manually fire the FireChangeEvent.

    _____________________________________________

    One of these should resolve your issue, provided the field is not relational. Relational fields and their interaction with the firechangeevent may be repaired through the defect linked earlier.
    The reply is currently minimized Show
  • Accepted Answer

    Friday, May 18 2012, 05:40 AM - #Permalink
    0
    I can't get the workaround to work, and DEF210025 isn't fixed in R10.1.1.1 so I'm stuck.

    I have very simple JS to read a field and set the value of a relational field. This works. However, the subrelational field based on that relational field never gets populated. I've tried everything I can think of in JS and in Form Actions but Change Event never gets fired.
    The reply is currently minimized Show
Your Reply

Recent Tweets