I send form errors from Play side to front end like this:
JsError.toJson(errors)
And on front end I got something like this:
{"obj.comment":[{"msg":["error.minLength"],"args":[10]}],"obj.name":[{"msg":["error.path.missing"],"args":[]}]}
I need to know how to check if I have error for specific field and if there is error get messages for this field.
Is it possible to use Play Json in Scala.js?
You can't use Play Json, because it relies on reflection which Scala.js currently doesn't support.
Have a look a µPickle. It's a great lightweight JSON parser that works with Scala.js, because it doesn't use reflection. Check it out here.
Related
I recently got thrown into a company to do DD on a SaaS solution that needs to generate codes to send invites. Has anyone seen or used this method of passing an API key/auth code? It's using the Play Framework. I don't have access to the play source code, just a compiled binary so I can't even see how the GET request is validated.
Eg:
https://<site.com>/?auth=10002-1644542228446-75ac043770463c36039f29d75304171c
I checked the packages used and there is io.jsonwebtoken.jjwt-0.9.1.jar used but I'm only familiar with passing it as a header "Bearer ". and haven't seen this three segmented formatting. XXXXX-XXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Any help would be appreciated. I know it's not a lot to go off but I'm only looking to be pointed at the method used to get started.
I would like to know if it is possible to make a simple API call (e.g. GitHub API v3) within the context of a DocFx custom template preprocessor. I have been trying all sorts of different approaches, but nothing has fully worked so far.
My goal is to make a call to an API to retrieve some data, and then update the model accordingly to be used in the *.liquid or *.tmpl renderers.
I have tried using the http/https node modules. I have also tried using node-fetch. It results in a docfx build error something like:
Error:Error transforming model ".../index.raw.json" generated from
".../index.md" using "conceptual.html.primary.js". Error running
Transform function inside template preprocessor
According to DocFx documentation, preprocessors follow the ES 5.1 standard. My code conforms to this.
Does anyone know if this is possible?
By the way, I am able to do simple model manipulation just fine, so I understand the basic concepts here with the DocFx preprocessors.
Thanks!
For the benefit of others, I discovered DocFX uses jint which cannot require a Node library directly. Therefore, it appears the plugin route is a better way to go for this use case.
I use Play! Scala 2.4 with scala js, and I would like to know if there is a way to get the routing config file from the scala js files.
It would be very convenient since it would allow me to replace urls as string by something like application.routes.Application.admin().
Do you know any workaround to do this?
You can use javascript reverse routing.
It will help you to define routes from your js code.
It will look like this:
#helper.javascriptRouter("jsRoutes")(
routes.javascript.Application.admin
)
...
<script>
console.log(jsRoutes.routes.Application.admin())
</script>
Supporting the previous answer, you can take a look at my code for a rather complex real-world example.
The JavaScript side
The Scala.js facade around that
I've worked a lot with mapbox.js and just now dipping my feet into iOS. Everything is groovy but when working with a UTFGrid layer it seems like you can only get back flat html such as this when using RMInteractiveSourceOutputTypeTeaser
<strong>FID: </strong>182130<br>
<strong>Parcel: </strong>01000170-86<br>
<strong>Address: </strong>32 MONROE<br>
<strong>City: </strong>detroit<br>
is there anyway to get back something like a javascript object like what is returned from mapbox.js?
You don't necessarily get a JavaScript object back from the UTFGrid endpoint, for example see here:
https://a.tiles.mapbox.com/v3/justin.map-t5ae6kmf/8/152/103.grid.json
You get back whatever you've coded into the map, so you could encode a JSON string or whatever you want when making the map. See here for more info:
https://www.mapbox.com/tilemill/docs/crashcourse/tooltips/
I'm new at using Play Framework 2.0 (I am using Scala) and have a question about sessions.
I come from a Ruby on Rails background, so I tend to think of everything that I learn in Play Framework with respect to Ruby on Rails.
With that in mind, is there any way for me to call stuff stored in the Session while I am in the view?
If I have "hello" -> "world" stored in the Session, I want to be able to do something like #session.get("hello") and be able to use "world" in the view. Is this possible?
The other option I see is to store the value in a variable in the controller, and pass that along to the view by doing something like OK( var ), but that way seems kind of clunky especially if I start using more variables.
Thanks!
Sessions in Play store in cookies and are really just for cross-request data. If that is what you want then you can use #session.get("hello") but what you might actually be after is a way to pass stuff from controllers to templates without having to specify them as parameters. In that case, see the very detailed answer to that question here:
https://stackoverflow.com/a/9632085/77409
Yes you can use #session.get("hello") in template, however it looks that you need to specify at least implicit parameter named 'session' at the beginning of the template when using templates with Scala controllers:
#()(implicit session: play.api.mvc.Session)
Also there is flash scope - it differs from session that it lives only for one request and is not signed. So it is most often used just for transporting error/inf messages.
See Session and flash scopes doc
Finally as each template is just a Scala function, you can also call some action from your controller and retrieve session data
You can definetly call ur session in play templates.
Try this code - it works in views:
$session.session_variable_name;