Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Pre fill text field in a AEM custom component.

Avatar

Level 2

Hi, I am new to AEM and trying to make a thing in two steps.

First I am trying to pre fill a text field with text. Rigth now when i have some placeholder text that is there until the user starts the input. But i want it to be a valid input that can be left alone when the form is sent in.

Second: I want the text field (from above) to be filled with the title of a selected content fragment instead of a static text.

It currently looks like this, i assume the "sling:resoruceType" is what i have to change but i cant figure out to what.

fprogrammer_0-1694419535153.png

Any help is appreciated.

4 Replies

Avatar

Level 2

I found out you can solve the first problem by adding the a new row with name "Value" and then fill it in with static text on the value, but how it should get the value from the title is still beond me.

Avatar

Community Advisor

Hi, 

 

I think you could use the cq:template node, where you can pre-defined default properties, That way, if your user does not input anything, the property will be already there by default, the drawback with this is that this will work only if you drop the component for the first time, if this is a brand new component and has not been released to production you should be ok with this approach. 

You can read more here: http://www.sgaemsolutions.com/2018/02/cqtemplate-and-cqtemplatepath.html

 

If this custom component is already used, the best option is just to add a default value when the property is empty, you could do it directly in HTML or by using a Sling Model, something like this:

HTML:

<p>${properties.myTextProperty || 'My default value'}</p>

 

 

Hope this helps



Esteban Bustamante

Avatar

Administrator

@fprogrammer  Do you find the suggestion from Esteban useful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. 



Kautuk Sahni

Avatar

Level 2

So the solution he posted might be correct, the problem is that I am sadly not experienced enough to implement the solution he explains. A senior in my team believes the area of use is described is not the same for the question and solution.

(Sorry for being unclear, i am very new to aem)