Forums

Forums / Developing Portals / Show a text widget depending on the selected value of a lookup widget

Show a text widget depending on the selected value of a lookup widget

4 posts, 0 answered
  1. Graham Lee
    Graham Lee avatar
    8 posts
    Registered:
    19 Dec 2021
    16 Apr 2022
    Link to this post
    Hi,

    I'm trying to show a text widget depending on the selected value of a separate lookup widget. Does anyone have any idea's on how I can do this? I have tried using rule that executes when the lookup value changes. The executed script looks like this

    if(tpc.forms[0].kau_intendedfieldofstudy.get_value()=="??????"){
        tpc.forms[0].kau_otherfieldofstudy.show();}

    The kau_otherfieldofstudy text widget is set to hidden.

    I have had no luck and I'm unsure what value the get_value() returns. The documentation is unclear to me .

    Many thanks!





  2. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    18 Apr 2022 in reply to Graham Lee
    Link to this post
    Hello Graham,

    There are a few ways you can do this. I would recommend using get_textValue() if you think the labels of these fields won't change often. The get_value() function returns the entity logical name and the encrypted GUID separated by a semi-colon (ie. account;00000000-0000-0000-0000-000000000000) - these GUIDs change on a per user basis and would be impossible to track.

    This should work for what you're trying to do:

    tpc.forms[0].kau_intendedfieldofstudy.add_valueChanged(function() {
        let theValue = this.get_textValue();
        if(theValue === "YOUR VALUE HERE") {
            // Show field 0
            tpc.forms[0].kau_otherfieldofstudy0.show();
            // Hide field 1
            tpc.forms[0].kau_otherfieldofstudy1.hide();
        } else if(theValue === "YOUR OTHER VALUE HERE") {
            // Do something else
        }
    });

    If you'd like to learn more about what you can do with The Portal Connector API take a look at these docs: https://www.crmportalconnector.com/developer-network/documentation/portal-connector-widgets/tpc-client-side-api/mvc-based/lookup

    Hope that helps,

    Brady
    TPC Web Developer
  3. Graham Lee
    Graham Lee avatar
    8 posts
    Registered:
    19 Dec 2021
    18 Apr 2022
    Link to this post
    Hi Brady,

    Thank you for the reply, I will give this a try!

    Graham
  4. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    18 Apr 2022 in reply to Graham Lee
    Link to this post
    Hello Graham,

    You're very welcome. Let me know how it goes for you and/or you have any questions!

    All the best,

    Brady
    TPC Web Developer
4 posts, 0 answered