Pre fill text field in a AEM custom component. | Community
Skip to main content
Level 2
September 11, 2023

Pre fill text field in a AEM custom component.

  • September 11, 2023
  • 3 replies
  • 1747 views

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.

Any help is appreciated.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Level 2
September 11, 2023

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.

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
September 12, 2023

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
kautuk_sahni
Community Manager
Community Manager
September 14, 2023

@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
Level 2
September 14, 2023

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)