I want to get default value when I select the checkbox and user defined value when I deselect it. | Community
Skip to main content
Level 3
November 3, 2022
Solved

I want to get default value when I select the checkbox and user defined value when I deselect it.

  • November 3, 2022
  • 1 reply
  • 651 views

For example in my dialog I have a textfield and a checkbox so if I check it I want to get title from current page and if I uncheck I want user to be able to give some title.
Similar functionality I saw in Teaser component but the difference there is the title can be taken for any of the page with provided link I want to limit it to current page.
Can anyone help me with the js for the same?

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

you can simply write logic in sling model, below is the sample code.  please check if this helps you.

 

public class Sample {

 

    @ValueMapValue

    @7392697

    private String flag;   //checkbox name

 

 @ValueMapValue

    @7392697

    private String title;

 

 

    @ScriptVariable

    private Page currentPage;

 

    @PostConstruct

    public void init() {

        try{

           

            if (flag !=null && flag.equals("true")){

                title = currentPage.getTitle();

            }

        }catch (Exception e){

            log.error("Exception Sling Model :{}", e.getMessage());

        }

 

    }

 

}

1 reply

Siva_Sogalapalli
Community Advisor
Siva_SogalapalliCommunity AdvisorAccepted solution
Community Advisor
November 3, 2022

you can simply write logic in sling model, below is the sample code.  please check if this helps you.

 

public class Sample {

 

    @ValueMapValue

    @7392697

    private String flag;   //checkbox name

 

 @ValueMapValue

    @7392697

    private String title;

 

 

    @ScriptVariable

    private Page currentPage;

 

    @PostConstruct

    public void init() {

        try{

           

            if (flag !=null && flag.equals("true")){

                title = currentPage.getTitle();

            }

        }catch (Exception e){

            log.error("Exception Sling Model :{}", e.getMessage());

        }

 

    }

 

}