OML GUI - callback 'edit'-element on input change (text changed)

NilsWaap
NilsWaap New Altair Community Member
edited August 2021 in Community Q&A

Hey Community,

I am creating a GUI with the OML-language.

I have created a callback function that is supposed to be called whenever I do a change in a "edit"-field.

image

The basic idea is to look through a list of items and show the matched items in the listbox below.

Edit-component:

image

callback:

image

best Regards

Nils

Answers

  • Roberta Varela_20843
    Roberta Varela_20843 New Altair Community Member
    edited August 2021

    Nils,

    First of all, I think it is better to use a global variable here (handles), in case you are not using it yet. If you already declared it as global, you need to add global handles again within your function so that its value will be retrieved there, modified etc.

     

    Then I suggest you do this:

    1. Get the string that has been written:

    yourstring = get(handles.filepathload,'string')

    2. Try to find the string within your original list

    origlist = get(handles.the_handle_of_the_full_list,'string')

    idx = find(contains(origlist,yourstring))

    3. Update the list

    newlist = origlist(idx)

    get(handles.the_handle_of_the_full_list,'string',newlist)

     

    Please be aware that I am using 2 different variables here because we should not overwrite the original list, since it will be used later when the search keyword changes.

    If the search is incremental, depending on the size of your original list we may need to handle it differently to be more efficient and faster.

    Regards,

    Roberta

  • NilsWaap
    NilsWaap New Altair Community Member
    edited August 2021

    Nils,

    First of all, I think it is better to use a global variable here (handles), in case you are not using it yet. If you already declared it as global, you need to add global handles again within your function so that its value will be retrieved there, modified etc.

     

    Then I suggest you do this:

    1. Get the string that has been written:

    yourstring = get(handles.filepathload,'string')

    2. Try to find the string within your original list

    origlist = get(handles.the_handle_of_the_full_list,'string')

    idx = find(contains(origlist,yourstring))

    3. Update the list

    newlist = origlist(idx)

    get(handles.the_handle_of_the_full_list,'string',newlist)

     

    Please be aware that I am using 2 different variables here because we should not overwrite the original list, since it will be used later when the search keyword changes.

    If the search is incremental, depending on the size of your original list we may need to handle it differently to be more efficient and faster.

    Regards,

    Roberta

    Hello Roberta,

    thanks for your help. I forgot to declare the global variable within the callback function.

    My actual idea is to call the function whenever there is a change of the edit-line's string. Like an 'onChange" event.

    Regards,

    Nils

  • Roberta Varela_20843
    Roberta Varela_20843 New Altair Community Member
    edited August 2021

    Nils,

    Then you can simply assign the callback to the edit uicontrol element, like you already did. With this, everytime you intervene on the editbox, the callback will be triggered.

    Regards,

    Roberta