The "model" in this case is the formEdit model not the form model. Unless I'm 
missing something completely, if you would want to go that way you would have 
to modify the info.magnolia.module.form.paragraphs.models.FormFieldModel class 
to somehow get default values when no value is found otherwise. This would 
still not solve the problem because you want the form only to be filled in the 
first time it loads. Once the user modifies data and submits the form you don't 
want the original values to be used anymore when a field is left empty.

The patch provided with http://jira.magnolia-cms.com/browse/MGNLFORM-117 solves 
this by letting you set a form state manually. Now you can overwrite 
handleTokenMissing() (which is only called when the form is loaded the first 
time) and pre-fill in all the values in a form state object.

Again: If I'm missing something, please enlighten me! ;-)

-will

On 12.01.2012, at 13:22, Jan Haderka wrote:

> I would think that if model assigned to given form is aware of values those 
> should be prefilled.
> Looking at different input fields they seem to be willing to fill in the 
> values if provided by model (e.g. from formEdit.ftl: 
> value="${model.value!?html}")
> 
> Or did I misunderstand your question?
> 
> HTH,
> Jan
> 
> 
> On Jan 5, 2012, at 4:48 PM, Will Scheidegger wrote:
> 
>> In the vain hope that the lack of answers to my question was only due to 
>> pre-x-mas-stress, allow me to re-post it – I do believe my need is not too 
>> uncommon...:
>> 
>> How can I get the form module to pre fill in a form when the user loads it 
>> the first time?
>>      - e.g. filling in the user profile info for a profile update form
>>      - e.g. fill in a default from and to date in a reservation form
>>      - and so on
>> 
>> Any pointers warmly appreciated!!!
>> 
>> Thanks!
>> -Will
>> 
>> On 17.12.2011, at 18:56, Will Scheidegger wrote:
>> 
>>> O.k., so I created a FormState and FormStepState object and filled in all 
>>> the values I needed... but forgot to set the FormState object in the 
>>> FormEngine. Unfortunately you cannot do this because there is no setter 
>>> method for that and the attribute is private of course.
>>> 
>>> Therefore again to all the Form Module gurus: What is the proper way to 
>>> fill data into a form?
>>> 
>>> Thanks!
>>> -will
>>> 
>>> On 17.12.2011, at 11:59, Will Scheidegger wrote:
>>> 
>>>> Dear Magnolians
>>>> 
>>>> I'm trying to "upgrade" a custom profile update form to the STK PUR form. 
>>>> However when you open the form all fields are empty. I would like to auto 
>>>> fill in all of the form values by reading them from the current user – all 
>>>> except the password. Of course these values should only be filled in once. 
>>>> If the user removes the data from a field it should stay empty. 
>>>> 
>>>> Is there an easy way to achieve this? 
>>>> 
>>>> I've tried to write a custom form engine with the "handleTokenMissing()" 
>>>> method below. It is called and goes through all fields, creates FormField 
>>>> objects for every field and set's the value. However the form still does 
>>>> not display the value set in this method... so I guess I'm still missing 
>>>> something. Any ideas?
>>>> 
>>>>     @Override
>>>>     protected View handleTokenMissing() throws RepositoryException {
>>>>         // create a form state
>>>>         FormState formState = FormStateUtil.createAndSetFormState();
>>>>         // we need a step
>>>>         FormStepState step = new FormStepState();
>>>>         step.setParagraphUuid(this.getConfigurationNode().getUUID());
>>>>         formState.addStep(step);
>>>> 
>>>>         if (SecurityUtil.isAuthenticated()) {
>>>>             User user = MgnlContext.getUser();
>>>>             // auto fill in the values from the user
>>>>             if (this.getConfigurationNode().hasContent("fieldsets")) {
>>>>                 Iterator itFieldsets = 
>>>> this.getConfigurationNode().getContent("fieldsets").getChildren().iterator();
>>>>                 while (itFieldsets.hasNext()) {
>>>>                     Content fieldset = (Content) itFieldsets.next();
>>>>                     if (fieldset.hasContent("fields")) {
>>>>                         Iterator iterator = 
>>>> fieldset.getContent("fields").getChildren().iterator();
>>>>                         while (iterator.hasNext()) {
>>>>                             final Content node = (Content) iterator.next();
>>>>                             if (node.hasNodeData("controlName")) {
>>>>                                 final String controlName = 
>>>> node.getNodeData("controlName").getString();
>>>>                                 FormField field = new FormField();
>>>>                                 field.setName(controlName);
>>>>                                 if (controlName.equals("password") || 
>>>> controlName.equals("passwordConfirmation")) {
>>>>                                     // skip this!
>>>>                                 } else {
>>>>                                     try {
>>>>                                         
>>>> field.setValue(BeanUtils.getProperty(user, controlName));
>>>>                                     } catch (Exception ex) {
>>>>                                         if (user.getProperty(controlName) 
>>>> != null) {
>>>>                                             
>>>> field.setValue(user.getProperty(controlName));
>>>>                                         }
>>>>                                     }
>>>>                                 }
>>>>                                 step.add(field);
>>>>                             }
>>>>                         }
>>>>                     }
>>>>                 }
>>>>             }
>>>>         }
>>>>         View view = getFormView(step);
>>>>         return view;
>>>>     }
>>>> 
>>>> 
>>>> Thanks!
>>>> -will
>>>> 
>>>> 
>>>> 
>>>> ----------------------------------------------------------------
>>>> For list details, see 
>>>> http://www.magnolia-cms.com/community/mailing-lists.html
>>>> Alternatively, use our forums: http://forum.magnolia-cms.com/
>>>> To unsubscribe, E-mail to: <[email protected]>
>>>> ----------------------------------------------------------------
>>> 
>>> 
>>> 
>>> ----------------------------------------------------------------
>>> For list details, see 
>>> http://www.magnolia-cms.com/community/mailing-lists.html
>>> Alternatively, use our forums: http://forum.magnolia-cms.com/
>>> To unsubscribe, E-mail to: <[email protected]>
>>> ----------------------------------------------------------------
>> 
>> 
>> 
>> ----------------------------------------------------------------
>> For list details, see 
>> http://www.magnolia-cms.com/community/mailing-lists.html
>> Alternatively, use our forums: http://forum.magnolia-cms.com/
>> To unsubscribe, E-mail to: <[email protected]>
>> ----------------------------------------------------------------
> 
> 
> 
> 
> ----------------------------------------------------------------
> For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
> Alternatively, use our forums: http://forum.magnolia-cms.com/
> To unsubscribe, E-mail to: <[email protected]>
> ----------------------------------------------------------------



----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to