Customer Portal

Get Involved. Join the Conversation.

Topic

    Aparajit Malli
    Extending OOTB "SearchButton" Widget to make...Answered
    Topic posted July 17, 2019 by Aparajit MalliBlue Ribbon: 750+ Points 
    31 Views, 2 Comments
    Title:
    Extending OOTB "SearchButton" Widget to make fields required for search
    Summary:
    I need help extending OOTB "SearchButton" widget. We need to make certain fields required to allow search for the customer.
    Content:

    We have a required to search on patients (basically, contacts with Type=Patient). But, we need to make certain fields required to allow the search on patients. So, I tried extending the OOTB "SearchButton" widget. 

    I got the alert working in when the "Search" button is clicked without the "First Name" field but the search still goes through (it does not seem to be blocking the search). 

    I understand when I am extending the javascript - I will inherit everything the parent. 

    But, how do I block the execution for the search when a Required field (First Name) is missing? 

    Attached is the code.. Please help me!

     

     

     

    Code Snippet:

    Best Comment

    Aparajit Malli

    Thanks for the reply, Jared!

    I figured out the issue.

    1) I used "force_flip_page" = TRUE which forced the page to refresh instead of AJAX.

    Also, figured out that when a search is done, it adds parameters on the URL.

    For example, searching [First Name] = John produces this URL..

    http://xx.custhelp.com/app/your_page/st/2/page/1/FirstName/John

    Then, the search seems to extract the parameters from this URL and sends to the report as filters.

    2) I created a custom Text Filter for the report to search on First Name & Last Name - which also subscribes to the search event (as referenced below).

    this.searchSource().on("search", function(){return this._eo;}, this)
                .on("reset", this._onResetRequest, this);

    Once these 2 issues were handled, I am able to make it work..

     

    Thanks,

    Aparajit

     

     

    Comment

     

    • Jared Ennew

      Hi Aparajit

      You could try wrapping the call to this.searchSource() in a condition that first checks if the First Name field contains a value:

      if (this.Y.one('#[inputid]').get('value') != "" || this.Y.one('#[inputid]').get('value') != null) {

      this.searchSource().fire("search", new RightNow.Event.EventObject(this, {filters: {
                      report_id: this.data.attrs.report_id,
                      source_id: this.data.attrs.source_id,
                      reportPage: searchPage,
                      newPage: this.data.attrs.force_page_flip || top !== self || (searchPage !== "" && searchPage !== "{current_page}" && !RightNow.Url.isSameUrl(searchPage)),
                      target: this.data.attrs.target,
                      popupWindow: this.data.attrs.popup_window,
                      width: this.data.attrs.popup_window_width_percent,
                      height: this.data.attrs.popup_window_height_percent
                  }}));

      } else {

      alert("some message - First name required etc...");

      }

    • Aparajit Malli

      Thanks for the reply, Jared!

      I figured out the issue.

      1) I used "force_flip_page" = TRUE which forced the page to refresh instead of AJAX.

      Also, figured out that when a search is done, it adds parameters on the URL.

      For example, searching [First Name] = John produces this URL..

      http://xx.custhelp.com/app/your_page/st/2/page/1/FirstName/John

      Then, the search seems to extract the parameters from this URL and sends to the report as filters.

      2) I created a custom Text Filter for the report to search on First Name & Last Name - which also subscribes to the search event (as referenced below).

      this.searchSource().on("search", function(){return this._eo;}, this)
                  .on("reset", this._onResetRequest, this);

      Once these 2 issues were handled, I am able to make it work..

       

      Thanks,

      Aparajit