There is a need to perform parsing of data from textarea and keep it safe on page update to let it be easily changeable for further experiments.
Before I have added the Silhouette to the app everything was pretty ok.
The page was getting the input parameter:
#(textToParse: String)
and its value was passed to plain HTML tag like:
<textarea ...>#textToParse</textarea>
But when I have added the Silhouette and used the form field construtor, I have met a problem:
#import b3.inline.fieldConstructor
#b3.textarea(someForm("text"), 'rows -> "12", 'value -> "#textToParse")
displays hardcoded "#textToParse" instead of the parameter value.
Skipping the quotes ('value -> #textToParse) leads to compilation error:
Type mismatch: found (Nothing) => (Symbol, Nothing), required (Symbol, Any)
I have checked the documentation on offsite http://silhouette.mohiva.com/docs/ and googled, but with no result.
Any working suggestions will be much appreciated!
Your code must look like:
#b3.textarea(someForm("text"), 'rows -> "12", 'value -> textToParse)
With Twirl, the Play template engine, you start an expression with the # sign. So in your case you start the expression with the Bootstrap 3 form helper. All other which is in the expression must be normal Scala code.
Related
By looking an introductory tutorial on how to use SQLite in Swift (in the iOS context), I saw the following line of code:
let queryString = "INSERT INTO Heroes (name, powerrank) VALUES (?,?)"
tutorial URL : https://www.simplifiedios.net/swift-sqlite-tutorial/
I don't understand if this is a Swift feature of something which will be parsed by SQL
It it some kind of string interpolation, like:
var s = "The value is \(value)"
Or is it something else?
This other tutorial sheds some light regarding the meaning of said syntax:
https://www.raywenderlich.com/6620276-sqlite-with-swift-tutorial-getting-started
It says:
Here, you define a value for the ? placeholder. The function’s name — sqlite3_bind_int() — implies you’re binding an Int to the statement.
The first parameter of the function is the statement to bind to, while the second is a non-zero-based index for the position of the ? you’re binding to. The third and final parameter is the value itself. This binding call returns a status code, but for now, you assume that it succeeds.
I have a form where a field name is the same as one of the method/url parameters on the submit, say someInt. I.e. my form has #(dummyForm:Form[Dummy], someInt:Int) and dummyForm has a field "someInt" -> number and the controller is defined as def submit(someInt:Int) =.... Sample code here.
Let's say I submit the form with dummy.someInt value 222 and url parameter 555, I find the following:
request.body.asFormUrlEncoded shows one someInt, namely the value entered in the input field: (someInt,ArrayBuffer(222))
bindFromRequest, however somehow binds the form value to the url parameter value, 555 in this case
Is this expected behaviour? I would have thought bindFromRequest would be able to differentiate between the two? Is there a preferred way to prevent this type of conflict (besides having different names)?
(There is a workaround in this case. Instead of using the parameterless version of bindFromRequest, it seems to work as desired if you explicitly specify the asFormUrlEncoded set of values, i.e. bindFromRequest(request.body.asFormUrlEncoded.getOrElse(Map())). I am using Scala - have not tried to replicate in Java.)
In the bindFromRequest function, request.queryString is explicitly append to the list of values.
I'm fairly new to Play 2 (Scala). I need to use pagination to output the members of a list. This is easy enough, except the pagination part.
In my route file I have my search:
GET /find/thing/:type controllers.Application.showType(type: String)
This works fine if I wanted to dump the entire list to the page.
Now, what if I want to paginate it? I suppose I could do -
GET /find/thing/:type/:page controllers.Application.showType(type: String, page: Int)
But then what happens if the user just types "myurl.com/find/thing/bestThing" without the page? Clearly there will be an error when it should automatically "default" to page 1.
Is there a way to default these arguments? If not, what is the best practice for this?
Thank you!
Two options:
declare both routes you mentioned (first using parameter with fixed value), then you can use untrail trick globally, in such case it will redirect your /find/thing/something/ to /find/thing/something (page=1)
You can use parameters with default values, then your route will be like:
GET /find/thing/:type controllers.Application.showType(type: String, page: Int ?= 1)
and genereted URL will be like:
/find/thing/something?page=123
You could use a query string parameter instead of a path parameter for the page number. Query string parameters will allow you to provide default values for when the parameter is missing.
GET /find/thing/:type controllers.Application.showType(type: String, page: Int ?= 1)
You would use them like this:
/find/thing/bestThing?page=3 // shows page 3
/find/thing/bestThing // shows page 1
I'm looking for a way of saving and after handling the arguments of a web form in SWI-Prolog when I submit the form and I call the same program to generate another form and so on. Always calling the same prolog program from one form to the next one.
The CGI SWI-Prolog library saves these arguments as a list of Name(Value) terms, i.e [Name(Value)].
if I pass the arguments like a hidden argument inside the form (TotalArguments is a list):
format('"<"input type="hidden" id="nameofform1" name="nameofform1" value="~w" />~n', TotalArguments),
I need to get rid of the id or name that concatenates on my resultant list on TotalArguments when I append it. Any idea of how to do this so that the final list looks like [nameofform1(value1), nameofform2(value2),...]?
I could also write this list of arguments and append it into a file, and consult it every time the program is called again, but this will load them always and I only need to load the arguments needed in the specific step and form handled at the moment. Because otherwise this file could contain undesirable info after some executions. Any thoughts on how to do it this way?
Any other suggestions for this kind of problem?
Edit with my solution using hidden form
I've solved it by creating:
extract_value([],_).
extract_value([A0|__ ], Valor) :-
A0 =.. [_, Value],
Valor is Value.
and then doing:
extract_value(Arguments, Value),
and submiting the hidden value of the form like:
format('<"input type="hidden" id="nameofform1" name="nameofform1" value="~w"/>~n', [Value]),
and appending it in the next form so that it looks how I wanted:
[nameofform2(value2),nameofform1(value1)]
It's a bit unclear to me what exactly you need here, but to remove the first element of a list that unifies with a given element (especially if you know for certain that the list contains such an element), use selectkchk/3. For example:
selectchk(id(_), List0, List1),
selectchk(name(_), List1, List)
in order to obtain List, which is List0 without the elements id(_) and name(_). Kind of implicit in your question, as I understand it, seems to be how to create a term like "form1(Value)" given the terms name(form1) and Value. You can do this for example with =../2. You can create a term T with functor N and arguments Args with
T =.. [N|Args]
It does not seem necessary to write anything to files here, I would simply pass the info through forms just as you outline.
I have the following code:
$("#auto").autocomplete({
source: "js/search.php",
minLength: "3" });
This code is assign to an input text box where i type a name and after 3 letters it should return the ones that have similar letters. For my case it is returning all values, even those not related to the 3 letters already typed. My question is:
How to send my search.php file the value inside the input so it should know what to search for. For the moment it searches for everything. I checked the value that was going to php and it was empty. Since the query to mysql uses LIKE '%VARIABLE%' and the variable is empty it searches for '%%' which is all cases.
How can i send the correct informacion from JS to PHP with the simplest form.
Here is the explanation :
http://www.simonbattersby.com/blog/jquery-ui-autocomplete-with-a-remote-database-and-php/
Regards