Change color of field based on another fields value

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Jaydius
Posts: 43
Joined: Thu Nov 12, 2015

30 Apr 2018

I have one field that has color choices (Red, Green). Based on the choice in this field, how can I change the background color of another field to the color selected?

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

01 May 2018

Dear Jaydius,
That should be doable, but it depends on what type of field you want to change background of. Do you want the background to save or be only visible when the form is opened?
Cheers

Jaydius
Posts: 43
Joined: Thu Nov 12, 2015

04 May 2018

Just wanting to change the background of a standard text field. Ideally showing on 'View' and 'Edit' forms.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

04 May 2018

Dear Jaydius,
For standard text field, you can use the following code on Edit form to change background color:

Code: Select all

fd.field('Title').control()._el().find('input').attr('style', 'background-color: #EE5050;')
For Display Form, use the following code:

Code: Select all

var style = fd.field('Title').control()._el().attr('style');
fd.field('Title').control()._el().attr('style', 'background-color: #EE5050;' + style);
How to detect change in Choice field, you can find in the following article - https://spform.com/javascript-framework ... eld-values
Cheers

Jaydius
Posts: 43
Joined: Thu Nov 12, 2015

07 May 2018

Thank you Nikita, works perfectly! Really appreciate your help.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 17 guests