Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Color of a field based on value selection from dropdown
-
- Posts: 41
- Joined: Thu Jan 25, 2018 3:51 pm
Color of a field based on value selection from dropdown
Hi,
Can this be possible to achive?
Background color of the field need to be changed after save based on the value selection from drop down.
Thank you very much for your help in advance.
Regards,
Sandeep
Can this be possible to achive?
Background color of the field need to be changed after save based on the value selection from drop down.
Thank you very much for your help in advance.
Regards,
Sandeep
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: Color of a field based on value selection from dropdown
Hi,
Place this code to your form’s Javascript section (Options Menu -> Form Properties -> Custom Code -> JS)
Place this code to your form’s Javascript section (Options Menu -> Form Properties -> Custom Code -> JS)
Code: Select all
function colorSelect(f) {
var val = $('#' + f).val();
var bgcolor;
switch(val) {
case '0':
bgcolor = 'green';
break;
case '1':
bgcolor = 'red';
break;
default:
bgcolor = 'white';
}
$('#' + f).css('background-color', bgcolor);
$('#' + f + ' option').css('background-color', 'white');
$('#' + f + ' option').css('color', 'black');
}
if (nuFormType() == 'edit' && nuCurrentProperties().record_id != '-1') {
colorSelect('YOUR_FIELD'); // <-------------- Replace with your field ID
}
-
- Posts: 41
- Joined: Thu Jan 25, 2018 3:51 pm
Re: Color of a field based on value selection from dropdown
Thank you very much quick response tom. It is working perfectly with in the form. However, when i tried it in subform nothing happening. any suggestion please?
I tried keeping the code in main form adding subform_id.field_id in thelast line of code. but no luck
I tried keeping the code in main form adding subform_id.field_id in thelast line of code. but no luck
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: Color of a field based on value selection from dropdown
Is your subform type "Grid" or "Form" ?
You do not have the required permissions to view the files attached to this post.
-
- Posts: 41
- Joined: Thu Jan 25, 2018 3:51 pm
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: Color of a field based on value selection from dropdown
Try something like this (untested):
Code: Select all
function colorSelect(f) {
var val = $('#' + f).val();
var bgcolor;
switch(val) {
case 'OK':
bgcolor = 'green';
break;
case '1':
bgcolor = 'red';
break;
default:
bgcolor = 'white';
}
$('#' + f).css('background-color', bgcolor);
$('#' + f + ' option').css('background-color', 'white');
$('#' + f + ' option').css('color', 'black');
}
if (nuFormType() == 'edit' && nuCurrentProperties().record_id != '-1') {
$('[id ^=sub_monthly_emp_status][id $=emp_status]').each(function () {
colorSelect($(this).attr('id'));
})
}
Last edited by Anonymous on Mon Aug 13, 2018 6:31 pm, edited 1 time in total.
-
- Posts: 41
- Joined: Thu Jan 25, 2018 3:51 pm
Re: Color of a field based on value selection from dropdown
just removed on closing } and tried with code by replacing sub_form_id and field_id but no luck.
Code: Select all
function colorSelect(selector) {
var val = $(selector).val();
var bgcolor;
switch (val) {
case 'ABC':
bgcolor = 'green';
break;
case 'DEF':
bgcolor = 'red';
break;
default:
bgcolor = 'white';
}
$(selector).css('background-color', bgcolor);
$(selector + ' option').css('background-color', 'white');
$(selector + ' option').css('color', 'black');
}
if (nuFormType() == 'edit' && nuCurrentProperties().record_id != '-1') {
$('[id ^=sub_monthly_emp_status][id $=emp_status]').each(function () {
colorSelect($(this).attr('id'));
}
) }
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
-
- Posts: 41
- Joined: Thu Jan 25, 2018 3:51 pm
Re: Color of a field based on value selection from dropdown
Thank you very much Tom. It is working perfect.. Once again thanks.
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am