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

Question

Question

If a Table Field Contains the Word "Drawing", Do Something

asked on July 18, 2019

I have two tables (#q7 and #q85 are the Table IDs for the Affected Docs and New Docs tables). First, let me provide a little history. When a user checks the "Yes" radio button, it checks the QA Project Support box and disables it so it cannot be changed. This function is working nicely:

Here's the working code for that:

$(document).ready(function(){

//Fills in Output Field with Affected (#q7) and New (#q85) Docs
  function populateTextArea(){
    var str = '';
//  Use the Table ID instead
  $('#q7 tbody tr, #q85 tbody tr').each(function(){
    if (str != '') str = str+'; ';
      var fieldCheck = $(this).find('.docID input').val() || ''; //If input has no value, set to blank and not run through fields.
      if (fieldCheck != ''){
     str = str+$(this).find('.docID input').val()+'-'+$(this).find('.docNo input').val()+'-'+$(this).find('.revision input').val();
      }
    });
  $('.output textarea').val(str);
  }
// q7 and q85 are the Table IDs
  $('#q7, #q85').on('change blur', populateTextArea);
  $('#q7, #q85').on('click blur', populateTextArea);
//The code below will wait 1 second before triggering the text population. Useful if Table rows are being populated from database.
  setTimeout(function(){
  populateTextArea(); //Call function
  },1000); //End setTimeout

});  //close document.ready

Now for my issue. Using these same two tables, if docIDDescription = Drawing (not Drawing Checkprint, Fabrication Drawing, or Fabrication Drawing Checkprint) in either of these two tables, I need to check the "discipline" boxes and disable them:


Here's what I have so far, but it's not working:

$(document).ready(function(){

//Checks Affected (#q7) and New (#q85) Docs tables for Drawings, if any Doc ID Description = Drawing, per procedure update, all disciplines must review the DCR
  function checkDocIDDesc(){
//  Use the Table ID instead
  $('#q7 tbody tr, #q85 tbody tr').each(function(){
    $(this).find('.docIDDesc input').val()
    if ($(this).val() == "Drawing")
    {
      $("#Field104-0").prop("disabled", false); //Enable so it can be changed
      $("#Field104-0").prop("checked", true).change(); //Drafting and Design is Required
      $("#Field104-0").prop("disabled", true); //Disable so it cannot be changed

      $("#Field104-1").prop("disabled", false); //Enable so it can be changed
      $("#Field104-1").prop("checked", true).change(); //Nuclear Analysis is Required
      $("#Field104-1").prop("disabled", true); //Disable so it cannot be changed

      $("#Field104-3").prop("disabled", false); //Enable so it can be changed
      $("#Field104-3").prop("checked", true).change(); //Structural Analysis is Required
      $("#Field104-3").prop("disabled", true); //Disable so it cannot be changed

      $("#Field104-4").prop("disabled", false); //Enable so it can be changed
      $("#Field104-4").prop("checked", true).change(); //Thermal Analysis is Required
      $("#Field104-4").prop("disabled", true); //Disable so it cannot be changed
    }
    else
    {
      $("#Field104-0").prop("disabled", false); //Enable so it can be changed
      $("#Field104-1").prop("disabled", false); //Enable so it can be changed
      $("#Field104-3").prop("disabled", false); //Enable so it can be changed
      $("#Field104-4").prop("disabled", false); //Enable so it can be changed
    }
  }
// q7 and q85 are the Table IDs
  $('#q7, #q85').on('change blur', checkDocIDDesc);
  $('#q7, #q85').on('click blur', checkDocIDDesc);
//The code below will wait 1 second before triggering the function.
  setTimeout(function(){
  checkDocIDDesc(); //Call function
  },1000); //End setTimeout

});  //close document.ready

Any assistance would be greatly appreciated!

0 0

Answer

SELECTED ANSWER
replied on July 24, 2019

OK, decided to use the same method used on "specification".  I set up a Yes/No radio button. If “Yes” is chosen, 4 checkboxes are checked and disabled.

Got that working no problem. Thanks for the feedback earlier.

0 0

Replies

replied on July 19, 2019

Anything? Anyone?

0 0
replied on July 19, 2019

I think your test is incorrect.

 

  $('#q7 tbody tr, #q85 tbody tr').each(function(){
    if ($(this).find('.docIDDesc input').val() == "Drawing"){
        stuff();
    }
});

 

0 0
replied on July 23, 2019 Show version history

UPDATE: Mostly worked! I'll deal with the on change or on blur in a different post. I used:

$(document).ready(function(){

//For Drawings, All Disciplines Must Review
  $('#q7 tbody tr, #q85 tbody tr').each(function(){
    if ($(this).find('.docIDDesc input').val() == "Drawing")
    {
      $("#Field104-0").prop("disabled", false); //Enable so it can be changed
      $("#Field104-0").prop("checked", true).change(); //Drafting and Design is Required
      $("#Field104-0").prop("disabled", true); //Disable so it cannot be changed

      $("#Field104-1").prop("disabled", false); //Enable so it can be changed
      $("#Field104-1").prop("checked", true).change(); //Nuclear Analysis is Required
      $("#Field104-1").prop("disabled", true); //Disable so it cannot be changed

      $("#Field104-3").prop("disabled", false); //Enable so it can be changed
      $("#Field104-3").prop("checked", true).change(); //Structural Analysis is Required
      $("#Field104-3").prop("disabled", true); //Disable so it cannot be changed

      $("#Field104-4").prop("disabled", false); //Enable so it can be changed
      $("#Field104-4").prop("checked", true).change(); //Thermal Analysis is Required
      $("#Field104-4").prop("disabled", true); //Disable so it cannot be changed
    }
    else
    {
      $("#Field104-0").prop("disabled", false); //Enable so it can be changed
      $("#Field104-1").prop("disabled", false); //Enable so it can be changed
      $("#Field104-3").prop("disabled", false); //Enable so it can be changed
      $("#Field104-4").prop("disabled", false); //Enable so it can be changed
    }
  });

});  //close document.ready

And here's what happened in testing:

For the q7 table, it checked my boxes (yay) but didn't disable them (almost like with went with the "else" too):

 

As long as q85 had "drawing" in the Doc ID Desc, it worked:

Gives me hope!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.