PiggyInTheMirror
PiggyInTheMirror

Reputation: 77

Achieving dependency on the Shuttle value in Oracle Apex

Good evening!

I'm making a page in Oracle Apex, which leads to creating a document. This page has many fields like "text field" or "select list" and so on with its own logic, and I've got stuck with two ones - the shuttle field (let it be named A) and the text field (let it be named B), which should depend on the first one. The scheme of their interaction is this:

The problem I have is that I can't make the field B to behave depending on field A values. I've already tried to use JavaScript function triggering from "onChange" event, which should have been working, if the right half of the shuttle B had got "others" value. But this way didn't work as I wanted, because "onChange" event arises on every click on both halfs of shuttle, and I need to have it arosen only on moving the value "others" (what can be done in two ways: on double click or due to click on arrow icon on shuttle).

So the question is: how to synchronize shuttle and text field in "master-detail" logic?

p.s. I'm using Oracle Apex 4.2.6.0003. Also I know that I can have a workaround, using only select lists, but I'd like to try to solve the problem with using shuttle, especially considering that the last one could have almost infinite count of values.

Upvotes: 1

Views: 980

Answers (1)

Tom
Tom

Reputation: 7028

With static values as list of values for shuttle:

STATIC:A;A,B;B,C;C,Others;OTHERS

Using jvascript code like this:

$("#P40_SHUTTLE").change(function(){
console.log(apex.item(this).getValue().indexOf("OTHERS") != -1);
})

Will return true when OTHERS has been selected (it is in the values of the shuttle). Change is the correct event to listen for here!

Translating that to a DA:

On change of the shuttle Use the "When" condition of type "JavaScript expression" and use this code:

apex.item(this.triggeringElement).getValue().indexOf("OTHERS") != -1 

You can then use the True and False actions of the DA to for example show and hide the text field as required. I'd not go further than that on the front end. Maybe show a required label for the textfield, as it'll only get shown when the field is shown. Add a server side validation (on submit) on the textfield where you'll inspect the shuttle values for the existence of the OTHERS value. If it's present, then the text field should be required.

Validation created on the textfield. Condition of type "PLSQL Function Body"

DECLARE
  l_vc_arr2    APEX_APPLICATION_GLOBAL.VC_ARR2;
BEGIN
  l_vc_arr2 := APEX_UTIL.STRING_TO_TABLE(:P40_SHUTTLE);
  FOR z IN 1..l_vc_arr2.count LOOP
    IF l_vc_arr2(z) = 'OTHERS' THEN
      RETURN TRUE;
    END IF;
  END LOOP;

  RETURN FALSE;
END;

Type of the validation: IS NOT NULL
Item: the text field.

The validation will only fire when others is present in the selected values, and then will require the text field to be required.

Upvotes: 1

Related Questions