Expand my Community achievements bar.

SOLVED

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

Avatar

Level 4

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?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

 

public class Sample {

 

    @ValueMapValue

    @Deleted Account

    private String flag;   //checkbox name

 

 @ValueMapValue

    @Deleted Account

    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());

        }

 

    }

 

}

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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

 

public class Sample {

 

    @ValueMapValue

    @Deleted Account

    private String flag;   //checkbox name

 

 @ValueMapValue

    @Deleted Account

    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());

        }

 

    }

 

}