• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Push Button background alternating colour to reveal another field

Engaged ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Hi all,

 

Am wondering if what I am hoping to achieve is possible - I have a button field (ICON_BUTTON) with the following script on 'Mouse Up' value, and that with each button press, alternates the background fill colour between black and transparent;

 

var f = this.getField(event.target.name);
if (color.equal(f.fillColor, color.black))
f.fillColor = color.transparent;
else
f.fillColor = color.black;

 

I have another field (LINE_1) that I would ideally like to alternate between either being visible (with a black button background showing), or hidden (with the transparent button background showing), the script being in the LINE_1 custom calculation script. Is this even possible?.

 

 

TOPICS
PDF forms

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct answers

Community Expert , Aug 30, 2020 Aug 30, 2020

OK, that's more clear. You can do it using this code under the button. Do not use a calculation script for this.

 

var f = event.target;
var f2 = this.getField("LINE_1");
if (color.equal(f.fillColor, color.black)) {
	f.fillColor = color.transparent;
	f2.fillColor = color.transparent;
} else {
	f.fillColor = color.black;
	f2.fillColor = color.black;
}

Votes

Translate

Translate
Community Expert , Aug 30, 2020 Aug 30, 2020

Change both f2.fillColor line  to f2.display = display.hidden and f2.display = display.visible

Votes

Translate

Translate
Community Expert , Aug 30, 2020 Aug 30, 2020

If you want to add codes to same button you can do it like this:

var f = event.target;
var f1 = this.getField("LINE_1");
var f2 = this.getField("LINE_2");
var f3 = this.getField("LINE_3");
if (color.equal(f.fillColor, color.black)) {
f.fillColor = color.transparent;
f1.display = display.hidden;
f2.display = display.hidden;
f3.display = display.hidden;

} else {
f.fillColor = color.black;
f1.display = display.visible;
f2.display = display.visible;
f3.display = display.visible;
}

Also you should check Try67 post a

...

Votes

Translate

Translate
Community Expert ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Yes... just use the same code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

If I getting what OP means your advice won't work.

Op asked if he can put code in custom calculation script field named "LINE_1" I'm guessing it's text field, that will show field if button fill color is black and hide it if button fill is transparent.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

The field type doesn't matter. What matters is what should trigger this change. If you put it in the calculation script of a text field it will constantly change each time any field in the file is edited.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

I tried it but it just set text field to black and doesn't change after that.Here is the file I tested it on example 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Again, the first step is to decide how it should work. When should the field change color? Then you select the event best suited for it and adjust the code to work under that event. Doing it the other way around is not going to work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Sorry I'm being such PITA but your advice is to use "same" code, and that don't work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Since you're not the OP and you don't know how they want it to work, let's wait until we hear from them...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Hi try67/Asim123,

 

Have now attached a file example to my original post, with hopefully a clearer description and idea of what i'm hoping may be possible?.

 

Many thnaks for your replies and help ;-).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

OK, that's more clear. You can do it using this code under the button. Do not use a calculation script for this.

 

var f = event.target;
var f2 = this.getField("LINE_1");
if (color.equal(f.fillColor, color.black)) {
	f.fillColor = color.transparent;
	f2.fillColor = color.transparent;
} else {
	f.fillColor = color.black;
	f2.fillColor = color.black;
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Well surprise suprise, I did tell you in my first post what OP is asking for and that your advice won't work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Well, then you could have also provided the code to do it, couldn't you? And you'll notice that the code I provided now is pretty much identical to the original code, with the single addition of the second field into it... The only major difference is where the code should go, which I couldn't answer until it was more clear how they wanted it to work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Look Try67 I'm not trying to be smart ass if i knew code i would share it with OP but I din't know how to do it.

Sry if i sounded rude but I was just trying to point out that your advice was not correct. and that OP wants something else.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Hi all,

 

Many thanks for all your help...and try67, the script you had was absolutely right - NesaNurani just added the final piece of the jigsaw - my bad in not explaining it all out properly in the first instance i think! apologies if i've created a scene....

 

😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Hi try67,

 

Many thanks, but the code seems to only change the fill colour of the background to LINE_1, as opposed to either being hidden or visible - i'm looking (if its possible) to have the LINE_1 field hidden if the ICON_BUTTON background colour is transparent in actual colour, and if the ICON_BUTTON background is black, then the LINE_1 field should be visible...

 

😉

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Change both f2.fillColor line  to f2.display = display.hidden and f2.display = display.visible

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Apologies for further thread creep....if i wanted to increase the following code to say more lines as well as LINE_1 e.g. also add the functionality for a LINE_2, LINE_3, LINE_4 etc.,etc - would this be plausible?.

 

Original code for just LINE_1;

 

var f = event.target;
var f2 = this.getField("LINE_1");
if (color.equal(f.fillColor, color.black)) {
f.fillColor = color.transparent;
f2.display = display.visible;
} else {
f.fillColor = color.black;
f2.display = display.hidden;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

LATEST

If you want to add codes to same button you can do it like this:

var f = event.target;
var f1 = this.getField("LINE_1");
var f2 = this.getField("LINE_2");
var f3 = this.getField("LINE_3");
if (color.equal(f.fillColor, color.black)) {
f.fillColor = color.transparent;
f1.display = display.hidden;
f2.display = display.hidden;
f3.display = display.hidden;

} else {
f.fillColor = color.black;
f1.display = display.visible;
f2.display = display.visible;
f3.display = display.visible;
}

Also you should check Try67 post as correct because I just gave you a tip, it's his code that makes it work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines