0
Is there a simple way (say, with a javascript snippet in a form action) to remove an option from a single-selection field dynamically?

Accepted Answer

Thursday, September 20 2018, 08:48 PM - #Permalink
0
Phil Bustin wrote:

Derek, It's Single drop-down list.


Try this.

David's solution is not correct.

var myField = jQuerySBM(GetFieldByName(""));
myField.find("option:contains('')").remove();


the text should not be the element in the array of options, because the text is not inside the attribute text, instead, it is a node text.
so you have to select the node with node text instead.
  • Phil Bustin
    more than a month ago
    Thank you, Derek (and all the others).
The reply is currently minimized Show
Responses (14)
  • Accepted Answer

    Tuesday, September 11 2018, 05:42 PM - #Permalink
    0
    Yes, you can use javascript/jquery/form actions to dynamically remove values from a field. On you form create an action to execute the following javascript based on your specific needs.

    All you need to do is replace and with your values.


    var myField = jQuerySBM(GetFieldByName("<field name>"));
    myField.find("option[text='<value to remove>']").remove();
    • Derek Lauw
      more than a month ago
      It should be with function name jQuerySBM as opposed to the $
    • David Sheaffe
      more than a month ago
      Correct Derek. I have been using this for quite a while and hadn't updated to change the $ (have edited my original post)
    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, September 12 2018, 09:04 AM - #Permalink
    0
    In jQuerySBM, is SBM actually the main table in the app? I have no knowledge of jQuery.
    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, September 12 2018, 09:06 AM - #Permalink
    0
    In short, this seems not to have worked. Unfortunately, I don't know a way of debugging it.
    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, September 12 2018, 09:08 AM - #Permalink
    0
    If it is helpful, this is my javascript snippet:

    var myField = jQuerySBM(GetFieldByName("PRIORITY"));
    myField.find("option[text='Critical']").remove();
    • David Sheaffe
      more than a month ago
      Hi Phil, try changing the field name from "PRIORITY" (ie, the field name on the table) to "Priority" - assuming that is how it is displayed on the form.
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, September 13 2018, 07:55 AM - #Permalink
    0
    Still not working. The condition is on Load, and I used a popup to confirm my other condition (transition = desired transition), and I added two conditions just to be sure: focus on Priority and change in Priority. Only the popup works.
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, September 13 2018, 07:55 AM - #Permalink
    0
    var myField = jQuerySBM(GetFieldByName("Priority"));
    myField.find("option[text='Critical']").remove();
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, September 13 2018, 07:57 AM - #Permalink
    0
    Would it be helpful to insert a couple of lines showing I got the field, and showing the options?
    • David Sheaffe
      more than a month ago
      Perhaps. Also, have you tried using Chrome Developer tools (or similar) to see if there is any errors on the form.

      When I am using this I have a really simple form action that is just "When this form is loaded, If FieldA = xxx, Then execute javascript ......" - and never had a problem.

      Maybe make the form action simpler and see if that makes any difference. (ie, just 'on load'). A final thing I can think of - is the really obvious - are the field name and the required value both spelt exactly the same in the script as how they are displayed.
    The reply is currently minimized Show
  • Accepted Answer

    Friday, September 14 2018, 05:00 AM - #Permalink
    0
    Phil Bustin wrote:

    Is there a simple way (say, with a javascript snippet in a form action) to remove an option from a single-selection field dynamically?


    Is your one Single drop-down list or allow searching?
    The reply is currently minimized Show
  • Accepted Answer

    Friday, September 14 2018, 05:00 AM - #Permalink
    0
    Phil Bustin wrote:

    Is there a simple way (say, with a javascript snippet in a form action) to remove an option from a single-selection field dynamically?


    Is your field a allow searching style one or the single drop-down list?
    The reply is currently minimized Show
  • Accepted Answer

    Monday, September 17 2018, 07:29 AM - #Permalink
    0
    Derek, It's Single drop-down list.
    The reply is currently minimized Show
  • Accepted Answer

    Monday, September 17 2018, 07:39 AM - #Permalink
    0
    David, Does GetFieldByName require the database field name, or the logical field name, or either? If I recall, it is either.
    • David Sheaffe
      more than a month ago
      I am not sure. I know that where I use it for removing a field value, I am using the display/logical name of the field (ie, Priority - not PRIORITY)
    The reply is currently minimized Show
  • Accepted Answer

    Monday, January 07 2019, 01:32 PM - #Permalink
    0
    I'm using this successfully:

    var myField = jQuerySBM(GetFieldByName("Priority"));
    myField.find("option:contains('Critical')").remove();

    Two questions:

    1) What commands would list only certain values?

    2) To remove multiple values, I assume I just add the same last line with the other values.
    The reply is currently minimized Show
  • Accepted Answer

    Tuesday, January 08 2019, 02:28 PM - #Permalink
    0
    The answer to 2) is Yes.
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, February 14 2019, 12:35 PM - #Permalink
    0
    This works with the Load condition, but not with the field change condition added. Any idea why, or how it can be fixed?
    The reply is currently minimized Show
Your Reply

Recent Tweets