Skip to main content
MadMich
Inspiring
March 9, 2017
Answered

align 2 text field boxes based on dropdown option

  • March 9, 2017
  • 1 reply
  • 929 views

I would like to align two text fields boxes based on a dropdown field with the option 'yes' or 'no'. if no is selected the two fields align.

Here is my code (custom calculate script of event target field) which aligns the event target field to the top left hand corner of the test field.

if (this.getField("dropdown").value != "No") {

event.target.rect = this.getField("test").rect

}

The trouble is the event target field is resized to that of the test field!  I just want the fields to be aligned not resized.
I've used the rect[1], rect[2] etc but can't seem to get it to work?

Thanks

This topic has been closed for replies.
Correct answer try67

OK, I think I get it now... This script should do that:

if (this.getField("dropdown").value != "No") {

    var r1 = this.getField("test").rect;

    var r2 = event.target.rect;

    var newRect = [r1[0], r1[1], r1[0]+(r2[2]-r2[0]), r1[1]-(r2[1]-r2[3])];

    event.target.rect = newRect;

}

1 reply

try67
Community Expert
Community Expert
March 9, 2017

You need to better explain the situation. Where is the field located originally, compared to the other field?

What kind of alignment do you want to perform (vertical/horizontal)? Do the fields have the same size?

Also, what needs to happen if the value of the drop-down is changed after the fields has been aligned?

MadMich
MadMichAuthor
Inspiring
March 9, 2017

Thanks for the reply...

The test field is in a fixed position, I basically want to reset the event target field to the same coordinates as the test field

I want them to be aligned to the top left coordinate of the test field (left and top edges), the fields are the same height but the lengths are different.

The dropdown has 2 selections, 'no' means the event field is reset as mentioned, 'yes' will move the field on another fields value which I've already worked out.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 9, 2017

OK, I think I get it now... This script should do that:

if (this.getField("dropdown").value != "No") {

    var r1 = this.getField("test").rect;

    var r2 = event.target.rect;

    var newRect = [r1[0], r1[1], r1[0]+(r2[2]-r2[0]), r1[1]-(r2[1]-r2[3])];

    event.target.rect = newRect;

}