You are viewing limited content. For full access, please sign in.

Question

Question

How to run JS when clicking on Save as Draft button

asked on November 14 Show version history

Hello,

 

I am using JS to make fields in a table read only based on what radio button they select. When they save as a draft those values in the read only fields are lost. To bypass this, I need to disable read only when they click on the Save as a Draft button. The ID of the button is ihSaveDraft. However the JS I have below doesn't trigger on that ID. I tried using the btn-primary class as well without any luck. Even the alert doesn't trigger.

   $('.ihSaveDraft').on('click',function() {
     alert('Test');
    $('.allowEdit input').attr('readOnly', false);
    $('.allowEdit input').attr('disabled', false);
    $('.allowEdit textarea').attr('readOnly', false);
    $('.allowEdit textarea').attr('disabled', false);
    $('.allowEdit select').attr('readOnly', false);
    $('.allowEdit select').attr('disabled', false);
  });

 

Here is the Save as draft element

<button id="ihSaveDraft" class="btn btn-primary" ng-if="ihd.item.$rights.saveDraft &amp;&amp; ihd.allowSaveDraftBtnForTaskReview" ng-disabled="ihd.saveDraftBtnDisabled" ng-click="ihd.saveDraft()" title="Save draft">
     Save draft
    </button>

Is what I'm attempting to do even possible? Does the JS to run on the save to draft button need to be different than action buttons? I know this would work for an action button.

 

Any help or insight would be appreciated.


Stephen

0 0

Answer

SELECTED ANSWER
replied on November 14

Just confirming - you are using the Classic Designer, correct?  (looking at your code, that's the assumption I am making, but you didn't tag your post either way).

I'm also assuming you have other code that is making the fields readonly and disabled based on the other radio button.

Based on those assumptions, my recommendation would actually be to tweak what you are doing when the radio button is modified.  Instead of making the fields both readonly and disabled, I find it's best to just make them readonly, and not disabled, in order to ensure the values save.

If you are actually making them read only from the Layout page, and then populating them with Javascript, you'll find that doesn't work to save the values.  In cases that I need to do that, I usually set them as Readonly in the Javascript instead of on the Layout page.  Like this (give any fields you want to obey this the javascriptReadOnly class): 

$(document).ready(function () {

  //make the javascriptReadOnly fields read-only - this has to be done via Javascript, 
  //not the Layout page otherwise the field values cannot be populated via Javascript.
  $('.javascriptReadOnly input').each(function() { 
    $(this).attr('readonly', 'true');
    $(this).removeClass('hasDatepicker');
    $(this).parent().find('.ui-datepicker-trigger').hide();
  });
  $('.javascriptReadOnly select').each(function() { 
    $(this).attr('readonly', 'true');
  });
  $('.javascriptReadOnly textarea').each(function() { 
    $(this).attr('readonly', 'true');
  });

});

 

2 0
replied on November 14

Thanks Matthew, always fun when working with other people's code. I removed the JS that disabled fields and that did resolve my issue. I appreciate your help.

 

Stephen

2 0
replied on November 14

Glad to hear that worked.

1 0

Replies

You are not allowed to reply in this post.
replied on November 14

Thanks Matthew, always fun when working with other people's code. I removed the JS that disabled fields and that did resolve my issue. I appreciate your help.

 

Stephen

You are not allowed to follow up in this post.

Sign in to reply to this post.