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

Question

Question

How to make a field table column a require field with Java in forms

asked on October 28, 2014

Hi guys and girls,

 

I want to make a require column field in a table with java when the radio button "Working" is selected. here my forms

 

So I want to make the worktype column a requirefield. I tried this script I got the " * " appear but the field is not realy a require field because I can submit the form witout field any data in the worktype field

$(document).ready(function() {
  $('#q44').click(function () {
     
    if($('input[value="Working (incl. Standby)"]').is(':checked')) //edit the value here to use your own.
       	{
        $(this).find('.HoursSum1 input').attr('required', 'True');  
        $('#q116 label').append('<span class="cf-required">*</span>');
        $('#q116 input').attr('required', 'True');  
        }
    else {     
		$('#q116 span.cf-required').remove();
        $('#q116 input').removeClass('required').removeAttr('required');
      	
    	}
  }); 
});

0 0

Answer

SELECTED ANSWER
replied on October 28, 2014

Scott Wilsons suggestion is likely to work. I cannot remember off hand but between the two of our responses we should have gotten it covered for you. I normally work with single line fields with the javascript stuff I've done, so I might be wrong on the exact means of referencing the dropdown.

0 0

Replies

replied on October 28, 2014

Use the CSS Class of the input field, not the overall field. 

$('.WorkType input').attr('required','True');

// For Making it not required
$('.WorkType input').attr('required'.'False');

You are targeting the entire field with the #q166 code, but you need to target the input field precisely, which is like its own entity inside another entity. It's easier to give that entity a CSS Class and program it directly.

 

One last thing, I am not 100% sure this code will work for the repeatable rows of the form. Might need to use a loop iterating through each row and applying that code to the "this" inside the loop

0 0
replied on October 28, 2014

I always have trouble referencing table columns by those IDs like you've shown... I've found it's better to add a CSS class and use that to select things in a table. It looks like you have a CSS Class associated with the field already, "WorkType", so then the only other problem would be that it's a dropdown element and not a single line field. You'll have to adjust the selector a little bit:

$('.WorkType select').attr('required','True');

 

0 0
SELECTED ANSWER
replied on October 28, 2014

Scott Wilsons suggestion is likely to work. I cannot remember off hand but between the two of our responses we should have gotten it covered for you. I normally work with single line fields with the javascript stuff I've done, so I might be wrong on the exact means of referencing the dropdown.

0 0
replied on October 28, 2014

Yes in my table I use drop down list so the select is the good one and both of you help me a lot on this

 

thanks

0 0
replied on October 28, 2014

Ok I give it a shot to see if with your great information I could make it work and let you know the result

 

thanks

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

Sign in to reply to this post.