Stale form after editing

Questions and answers for designing and implementing forms in Servoy

Stale form after editing

Postby nick1461658753 » Wed Sep 07, 2016 11:48 am

Hi,

I have a form (frm_excel_update_columns) that is loaded in a tab in another form (frm_excel_configure_columns).
It is added via code:

Code: Select all
elements.tab_update_column.addTab( "frm_excel_update_columns" );


when the form is loaded I have an onshow function that adds the values to a combobox in the form.

Code: Select all
function onShow( firstShow, event ) {
   if ( firstShow ) {
      var lv_valuelist = solutionModel.newValueList( 'user_queries', JSValueList.CUSTOM_VALUES );
      lv_valuelist.separator = ' ';
      lv_valuelist.customValues = forms.frm_excel_configure_columns.ValueList;
      var lv_form = solutionModel.getForm( 'frm_excel_update_columns' );
      var lv_field = lv_form.getField( 'cbbColumn' );
      lv_field.valuelist = solutionModel.getValueList( 'user_queries' );
   }
}


But I get this error:
Stale form(s) detected, form(s) were altered by the solution model without destroying them first
The form(s) that are stale (can also be a parent form if form inheritance is used) are:
Form name:'frm_excel_update_columns' with instances: [frm_excel_update_columns]

On line 53; witch is: lv_field.valuelist = solutionModel.getValueList( 'user_queries' );

Why am I getting this error? I'm filling the combobox onshow, on firstshow even...
How about pizza?
nick1461658753
 
Posts: 28
Joined: Tue Apr 26, 2016 10:19 am

Re: Stale form after editing

Postby patrick » Wed Sep 07, 2016 12:11 pm

When you add the form to the panel, it is instantiated and its onShow is fired. The form instance already exists at that point and you are trying to alter the form. That's why you get that error.

From what I understand your value list uses some constant values from your form variable, so it is fix. Why not simply create a value list and put the values from forms.frm_excel_configure_columns.ValueList there? I don't see why you need the solutionModel to do this. You can do it in the designer just fine.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3655
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Stale form after editing

Postby nick1461658753 » Wed Sep 07, 2016 1:20 pm

No the valuelist is not fixed, in another form, where an excel file is uploaded, I make a string with the different columns in that excel file, it's basically just Column1, Column2, but every file can have a different number of columns and to prevent users from selecting a column that does not exist in the file I create this custom string with only the columns that are found in this file.

I just call the public form variable in witch I placed the string, but the string is generated.

Also, I'm fairly new to servoy, so don't know all the tricks yet ;)
How about pizza?
nick1461658753
 
Posts: 28
Joined: Tue Apr 26, 2016 10:19 am

Re: Stale form after editing

Postby patrick » Wed Sep 07, 2016 2:07 pm

Then you could use application.setValueListItems(...)...
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3655
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Stale form after editing

Postby nick1461658753 » Wed Sep 07, 2016 2:33 pm

Yes, that worked, thank you :)

I filled the values in an array instead of a string and added them like this:
Code: Select all
application.setValueListItems("ColumnList",ar_valueList);


And now it works, no errors, and the correct number of rows :)
How about pizza?
nick1461658753
 
Posts: 28
Joined: Tue Apr 26, 2016 10:19 am

Re: Stale form after editing

Postby patrick » Wed Sep 07, 2016 2:38 pm

With the solutionModel you create or modify the design of your solution ("designTime"), so all the stuff you can do in the designer. That should only be used really where the design is not known or fixed at design time. In all other cases, you should use the "runtime" methods Servoy offers. application.setValueListItems() is the runtime method used to populate a custom value list per code. So that is your friend here.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3655
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany


Return to Forms

Who is online

Users browsing this forum: No registered users and 4 guests