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?
Who is viewing this page

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
    7 hours ago
    Thank you, Derek (and all the others).
The reply is currently minimized Show
Responses (11)
  • 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
      one week ago
      It should be with function name jQuerySBM as opposed to the $
    • David Sheaffe
      one week 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
      one week 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
      one week 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
      4 days 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
Your Reply

Recent Tweets

RT @TrainingsEdu: Potřebujete získat znalosti o produktu Micro Focus UCMDB, porozumět základním pojmům a aplikacím? Na kurzu Universal CMDB…

by Micro Focus Support