Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

[UI Script] Make Estimate field required


#1

The following UI script makes the Estimate field require on the test case form.

[code]name: Make Estimate required
description: Makes the Estimate field of test cases required
author: Gurock Software
version: 1.0
includes: ^cases/(add|edit)
excludes:

js:
(document).ready( function() { (’#estimate’).prev().append(’ *’)
('form').submit( function() { App.Validation.hideErrors(); if (.trim(('#estimate').val()) == '') { (’#content’).prepend(‘

Field Estimate is a required field.
’);
$(’#estimate’).addClass(‘error’);
return false;
}
}
);
}
);
[/code]

Regards,
Tobias


#2

This is a very nice little script, I’ve used it in our environment, the problem with it is that if user will be keep pressing Save the error message will be keep adding to the screen, instead of showing only one error message


#3

Thanks for reporting this! I’ve updated the script accordingly.

Regards,
Tobias


#4

Hi, I am using the same script however in the test plan creation screen in order to make ‘Milestone’ mandatory.

I am using the below code, however if the field is blank then everything works however the ‘Add Test Plan’ button is disabled thus the user can not submit the form again. Any ideas?

$(document).ready( function() { $('#milestone_id').prev().append(' <span class="required"><font color="#FE2E2E">*</font></span>') $('form').submit( function() { App.Validation.hideErrors(); if ($.trim($('#milestone_id').val()) == '') { $('#content').prepend('<div class="messages validationError errorPanel" style="display: block"><font color="#FE2E2E">Field Milestone is a required field.</font></div>'); $('#milestone_id').addClass('error'); return false; } } ); } );


#5

Hello Gavin,

Thanks for your posting. The original script is for the test case form and it’s not supported to use the same script for the test plans. I’ve modified the script for test plans (for TestRail 4.0 and later):

[code]name: Makes the Milestone field required for test plans
description: Makes the Milestone field required for test plans
author: Gurock Software
version: 1.0
includes: ^plans/(add|edit)
excludes:

js:
(document).ready( function() { (’#milestone_id’).prev().append(’ *’)
('form').submit( function() { App.Validation.hideErrors(); if (.trim(('#milestone_id').val()) == '') { (’#content-inner’).prepend(‘

Field Milestone is a required field.
’);
('#milestone_id').addClass('form-control-error'); setTimeout( function() { (’#accept’).show();
$(’#acceptDisabled’).hide();
},
0
);
return false;
}
}
);
}
);[/code]

I hope this helps and I look forward to your reply.

Regards,
Tobias


#6

Yes works without issue. Thanks


#7

You are welcome, Gavin!

Regards,
Tobias


#8

Time to bring back an old Topic :wink:

I need a script such as this, but I want it based only on if a State field (a custom field we have) is set to a particular value. And, I only want this script enabled for a particular project. Basically…

if my.project = “projecta” and testcase.field.somefield = “somevalue” make testcase.field.anotherfield required

I am a bit unsure how to do a project-based selection (i saw the an example of doing something similar to this for TestRuns, but not for actual TestCases, though it may be the same)


#9

Hey Jim!

You can use the UI script context to limit UI scripts to select projects:

It’s more difficult for case properties because they are not always available in the UI script context. As the last resort, you can use the case ID from the current URI and then use TestRail’s API to get all case details:

I’m not sure if this is an option or too much work/overhead just for making a field required, but please let me know in case anything is unclear or if you have any questions.

Cheers,
Tobias