Home Dynamic pass value in a Play2 scala template
Reply: 1

Dynamic pass value in a Play2 scala template

Vinod
1#
Vinod Published in 2018-02-13 12:27:03Z

I try to dynamically change value of its variable. Once onclick (Change Ticket ID ) button then execute onClickSendEmail and variable value should be change of tickedId. Its unable to update with newTickedId. I tried while create variable using @defining and individual calling by function also. So, Basically I got stuck. how it will be solve.

@(sender: String)
<!--@{var tickedId = "tickedId"}-->


@defining(sender.contains("@")) {isEmail =>
@main((if(isEmail) "Email" else "Chat") + " Messages - " + sender) {

    ...
    ...
    ...
<div>
 <a onclick="onClickSendEmail();return false;">
            Change Ticket ID
     </a>
</div>

@defining("getTicketId()") { tickedId =>

        @views.html.common.form.panel("Reply",controllers.routes.ChatMessageController.sendEmail(tickedId,sender),"Send"){
                <textarea id="emailArea" cols="100" rows="4" name="emailArea"></textarea>
        }


<script type="text/javascript">
            function onClickSendEmail() {
                tickedId= "NewUpdatedTicketId";
            }
     function getTicketId() {
             return "NewUpdatedTicketId";
            }
    </script>
 }
}
}
Csaba
2#
Csaba Reply to 2018-02-13 13:00:16Z

You should not mix Twirl templating with Javascript. It's a bad approach. The role for Twirl is to render HTML blocks. You can define conditions and variables here in order to dynamically change the HTML output. While with Javascript you can modify this rendered HTML output without reloading the page.
There are cases where you need to use a Twirl variable in Javascript, then you can do something like:

@(chartData: Html)

<script>
    let jsData = @twirlData; // where twirlData is an existing variable
    console.log(jsData)
</script>


Here's a link where you can read more.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.33347 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO