Skip to Content

SAPUI5 - How do I aggregate with formElement?

previously implemented aggregation with VBox. This gets all the 'questions' and creates a Text box for each....

<VBox items="{path: 'view>questions', templateShareable: true}">
    <items>
        <VBox templateShareable="true">
            <Text text="Question {view>OrderSequence}"/>                                                        
        </VBox>
    </items>
</VBox>

I need to do the same, but for formElements. Can this be done?

<f:formElements>
    <f:FormElement label="{i18n>radioLabel}">
        <f:fields>
            <Input value="{viewmodel>radioLabel}" id="__redioLabel"/>
        </f:fields>
    </f:FormElement>                                    
</f:formElements>

It doesn't seem to work with 'items'

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Nov 08, 2017 at 05:08 PM

    Yes, you can use the fields aggregation.

    <f:formElements>
    <f:FormElement label="{i18n>radioLabel}" fields="{path: 'viewmodel>path', templateShareable: true}">
            <f:fields>
                <Input value="{viewmodel>radioLabel}" id="__redioLabel"/>         
    </f:fields>     
    </f:FormElement>                             
    </f:formElements>

    Regards,

    Jamie

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 09, 2017 at 09:11 AM

    Thanks Jamie.

    This only works for a single array element.

    I've tried to use the formElements aggregation of FormContainer, but If there's more than one element (e.g. label and points), only the last form element is displayed (e.g. points).

    Any clues?

    The model : (viewmodel context is questions/0/

    	questions: [{
    					order: 1,
    					title: "",
    					criteria: "",
    					category: "",
    					competency: "",
    					points: 2,
    					pointsNo:0,
    					naAvailable: false,
    					naDescription: "",
    					commentsMandatory: false,
    					showScore: false,
    					addImage: false,
    					answers: [{
    						label: "Yes",
    						points: 2
    					},
    					{
    						label: "No",
    						points: 0
    					}]
    				}]
    

    The view:

    <f:FormContainer formElements="{path: 'viewmodel>answers', templateShareable: true}">
        <f:formElements>
    	<f:FormElement label="{i18n>radioLabel}">
    	   <f:fields>
    	      <Input value="{viewmodel>label}" id="__redioLabel"/>
    	   </f:fields>
    	</f:FormElement>
    	<f:FormElement label="{i18n>radioPoints}">
    	   <f:fields>
    	      <Input value="{viewmodel>points}" id="__radioPoints" width="15%"/>
               </f:fields>
    	</f:FormElement>							
       </f:formElements>
    </f:FormContainer>
    
    Add comment
    10|10000 characters needed characters exceeded

  • Nov 09, 2017 at 11:13 AM

    Solution was an aggregation on the Form element....

    Add comment
    10|10000 characters needed characters exceeded

    • For some strange reason, the data is now being pulled in fine from the model, but if I change ANY element of answers (any path), All questions paths are updated.

      E.g. say I have the current paths:

      questions/0/answers/(1 , 2, and 3)

      questions/1/answers/(1, 2, and 3)

      if I update ANY element in answers 1, 2, or 3, the answer is updated in BOTH question/0 AND question/1 .... !

      		
      		<f:Form id="formCustomRadio" visible="true" formContainers="{viewmodel>answers}">
      			<f:layout>
      			<f:ResponsiveGridLayout/>
      			</f:layout>
      			<f:formContainers>
      				<f:FormContainer title="Answer {viewmodel>sequence}">
      				<f:formElements>
      				<f:FormElement id="element1" label=" {i18n>radioLabel}">
      				<f:fields>
      					<Input value="{viewmodel>label}" id="__yesPoints"/>
      				</f:fields>
      			</f:FormElement>