Expand my Community achievements bar.

SOLVED

HOW TO SET WIDTH FOR THE FIELD IN REPEATING INSTANCE / SUBFORM

Avatar

Former Community Member

I am stuck with the code and was wondering if someone has any suggestion.

I have a following code that is working and accomplishes what I want;

Hides presence of the subform

devP4, every time I add new instance

if

(SubForm1.tblEst.estRow1.txtEst.rawValue.length > 4)

{

for

(var i = 0; i < 4; i++){

var oFisDevice = xfa.resolveNode("Form.subMain.SData.SDev.indVice["+i+"]");

oFisDevice.DDetails.devRes.devP4.presence = "hidden";

}

xfa.layout.relayout();

 

}

 

What I cannot figure out is how to set width of the field called txtComments under subform devP6 to 9in, at the same time.

The code I have now is below. It works but sets the width to only first instance. What am I missing?

xfa.resolveNode("Form.subMain.SData.SDev.DevP6.txtComments").w = "9in";

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

I created a sample with what I think you want .....have a looka md let me know what you think .....all of the code is on the click event of the button.

Paul

View solution in original post

8 Replies

Avatar

Level 7

Hi,

Reading from the "Help" (F1):

Note: Scripts that fire on layout:ready should not  do anything that would cause the layout of the form to change. For example, this  would include anything involving subforms or tables that grow or shrink, adding  fragments dynamically at run time, adding or removing subform instances, and  toggling the presence setting of an object between hidden and visible.

I would try the "initialize" event. Reading from "Help" (F1):

You can use this event to perform actions when an object is first created,  either as the result of a form filler action or during the form creation  process. For example, you can use this event to control settings for new  instances of a subform object that a form filler adds to the form by using a  button.

Good luck!

Stephen

Avatar

Former Community Member

Thank you. I cannot use it on initilize event and my code is currently on the click of the button. I

need it to be there. Click on the button supposed to hide subform and set this field's width to 9in.

Every time I click on the button I would love to  add new instance,hide on subform and set field size to 9in.

Hope that clarifies my previous post.

Avatar

Level 7

Hi,

I'm not sure if this is helpful. The Initialize event is a process event--it fires (and executes its scripts) every time you create a new instance--even those new instances created by a button click. Unfortunately, it fires when you first open the form. So, if setting the width when openning is alright, you can use this event without any conditions added.

Otherwise, you could put a "if" condition on the script to have it count the number of instances (or some other condition) and if it meets the condition then it can set the width.

Good luck!

Stephen

Avatar

Former Community Member

 

Let me put it this way.

Does anyone have a sample that demonstrates following. When the forms is rendered, there are 3 subforms.

Suform1 has Textfield1

Suboform2 has 6 Textfields (Textfield2,Textfield3,Textfield4,Textfield5,Textfield6)

Subform3 has Button1

If value entered in TextField1 is bigger then 4, every time when I click on Button 1, I want to:

add instance of Subform2 ,

hide Textfields2 and TextField3 and set widths of TextField4 to 9in.

When I click Button1 for the first time, it works as expected. When I add instance every other time, I hide Textfields2

and TextField3 but the width for TextField4 is unchanged.

Thank you,

Avatar

Correct answer by
Former Community Member

I created a sample with what I think you want .....have a looka md let me know what you think .....all of the code is on the click event of the button.

Paul

Avatar

Former Community Member

That is exactly what I was looking for. You made my day Paul!

Thank you so much.

Just one more thing... I want to learn from your sample...Can you please explain this line of code to me? 

xfa.resolveNode("Subform2["

+ i + "]").TextField4.x = xfa.resolveNode("Subform2[" + i + "]").TextField2.x

Avatar

Former Community Member

If we make Textfield4 9 in wide ....it will start from the current laocation of TextFiedl 4 (about 3/4 of the way across the page .....so I am assigning the x location of TextField 2 (the start of the row) to the start location of TextField4 so it will start at the beginning.

You are assuming that if we remove the two fields that all other fields will shift to the left. Because this is contained with a positioned subform that will not happen. You coudl make the subform flowed but flow Western Text and you would not have to do that.

Make sense?

Paul

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----