CA Service Management

 View Only
Expand all | Collapse all

Conditionally display of field

  • 1.  Conditionally display of field

    Posted Nov 17, 2014 02:08 AM

    Hi All,

     

    I would like to show/hide field i.e. text field if I select a checkbox field. Is it possible? I can show/hide field after I click save button using pdm_if, but how can I show/hide without click save button.

     

    Cheers



  • 2.  Re: Conditionally display of field

    Posted Nov 17, 2014 02:30 AM

    You can use jQuery functions that are now supported in SDM. You can search for examples on internet e.g.Show/Hide Field using Jquery based on user input - Stack Overflow



  • 3.  Re: Conditionally display of field

    Posted Nov 17, 2014 11:52 AM

    Hi there,

    I tried to hide or show a text field on user input value using jQuery , i can see the results (show/hide) only after save not dynamically, I believe we have send a request back to web engine to reload the page .

    Can any one tired this, please share your thoughts.

     

    Thanks,

    Venkat



  • 4.  Re: Conditionally display of field

    Posted Nov 17, 2014 12:22 PM

    You need to trigger a change on field value change it has nothing to do with webengine.

     

    Sent from my iPhone



  • 5.  Re: Conditionally display of field

    Posted Nov 18, 2014 11:37 AM

    Hi Gutis,

     

    Do you happen to hv simple sample on how to include the code in detail_in.htmpl?

     

    Cheers,



  • 6.  Re: Conditionally display of field

    Posted Nov 18, 2014 01:18 PM

    No, but try this quick example that on priority change will hide the urgency field, it will not hide the label  (I had no time to play with that)

    place the following code somewhere near <PDM_MACRO name=dtlReadonly hdr="Active?" attr=active>

     

    jQuery(function(){

     

    jQuery('select[name="SET.priority"]').change(function(){

      jQuery('select[name="SET.urgency"]').hide();

      }

    )});



  • 7.  Re: Conditionally display of field

    Posted Jan 29, 2016 04:35 AM

    Hi Gutis

     

    I'm not good with java, in my case I'm trying to keep analysts from adjusting urgency and impact when creating ticket. So i'm not sure how to adjust your code and set the change condition to one that says something like when ticket is on initial state hide impact and urgency.

     

    Please advise



  • 8.  Re: Conditionally display of field

    Posted Jan 29, 2016 05:21 AM

    Hi, i think in this case you don't need any java script just use tandart ca tags

     

    <PDM_IF $args.id == 0>

    <PDM_MACRO name=dtlReadonly hdr="Urgency" attr=urgency>

    <PDM_ELSE>

    <PDM_MACRO name=dtlDropdown hdr="Urgency" attr=urgency evt="onBlur='manual_modify();detailSyncEditForms(this)'" lookup=no>

    </PDM_IF>

     

    Ofcourse it may be troubles with some automatic stuff like urgency from category and etc, but us i remember they are also set from triggers, so 90% that this approach will work.



  • 9.  Re: Conditionally display of field

    Posted Jan 29, 2016 05:22 AM

    Eventually I got it right, this is the coed I worked on and placed it in the head of the form:

     

    <script>

    jq(document).ready(function(){

        jq(window).load(function(){

            //alert("Page loaded.");

      //Hide urgency and impact on page load (so for all status changes it will remain hidden on edit mode)

     

    jq('select[name="SET.urgency"]').hide();

    jq('select[name="SET.impact"]').hide();

     

        });

    });

    </script>



  • 10.  Re: Conditionally display of field

    Posted Jan 29, 2016 05:28 AM

    Personaly i prefer server side operations, i use javascript and jquery only when there is no other options. Since with the javascript you may always get in troubles when using different browsers.



  • 11.  Re: Conditionally display of field

    Posted Jan 29, 2016 06:22 AM

    I hear you and agree with you but thing is I had already tried your suggestion but problem is on creation of the ticket the hour glass goes on without stopping (at other sometimes it's not there) and if you try to save your ticket it gives you an error that reads "page load in progress - please wait for response". This goes on without stopping



  • 12.  Re: Conditionally display of field

    Posted Nov 19, 2014 02:43 AM

    <PDM_MACRO name=dtlCheckbox hdr="test" attr=string1>
    jQuery(function(){

    jQuery(':checkbox').change(function(){
      if(jQuery(this).is(':checked'))
            {
      jQuery('select[name="SET.urgency"]').hide();
      jQuery('label[for="df_2_0"]').hide();
      }
      else
      {
      jQuery('select[name="SET.urgency"]').show();
      jQuery('label[for="df_2_0"]').show();
      }
    }
     

    )});



  • 13.  Re: Conditionally display of field

    Posted Nov 19, 2014 03:24 AM

    That's very cool.  Now, if you have more than one checkbox on your form are they both going to fire this function?  How could you make the urgency-hiding behaviour specific to the 'test' checkbox if you also have a 'call back required' checkbox on the form?  And just as an aside, I suspect that the field's id or name [can't remember which it is!] ('df_2_0') may change if the urgency field is moved on the detail form, so be aware of that as you apply other mods.



  • 14.  Re: Conditionally display of field

    Posted Nov 19, 2014 05:20 AM

    <PDM_MACRO name=dtlCheckbox hdr="test" attr=string1>
    jQuery(function(){

    jQuery(':checkbox').change(function(){
      if(jQuery(this).attr('name') == 'CBX.string1')
      {
      if(jQuery(this).is(':checked'))
       {
     
      jQuery('select[name="SET.urgency"]').hide();
      jQuery('label[for="df_2_0"]').hide();
     
      }
      else
      {
      jQuery('select[name="SET.urgency"]').show();
      jQuery('label[for="df_2_0"]').show();
      }
      }
    }
     

    )});



  • 15.  Re: Conditionally display of field

    Posted Nov 24, 2014 01:45 PM

    how you catch hold of the label as "df_2_0" ? we have couple of custom drop-down elements trying to achieve the same..

    can you tell us how find the labels..

     

    Thanks,

    Venkat



  • 16.  Re: Conditionally display of field

    Posted Nov 24, 2014 02:05 PM

    You can use browsers development tools f12 in ie and firefox or addons like firebug for firefox to inspect the elements of the ticket

     

    Sent from my iPhone



  • 17.  Re: Conditionally display of field

    Posted Nov 24, 2014 02:13 PM

    Just iterated all the DOM elements to inspect elements.

    Thanks..



  • 18.  Re: Conditionally display of field

    Posted Jun 27, 2016 03:39 AM

    Hi Gutis,

     

    We have similar requirement.

    We have added 3 custom fields in detail_chg.htmpl page. One drop down and two date fields.

    In drop down we have values as "1. Permanent" and "2. Temporary".

    We want to display date fields "To_Date" and "From_Date" when user selects "02. Temporary" option from drop down.

    How can this be achieved?



  • 19.  Re: Conditionally display of field

    Posted Nov 19, 2014 10:55 AM

    You can also check how in the detail_pcat,  'Self-Service Symbol' has been implemented . 

     

    They have used a checkbox(Self-Service Include) and are toggling the Self-Service Symbol text-box using it.