I am running into an issue where by I want to pass form elemets that gets generated dynamically as such id's of those elements are dynamic as well.
Here is the code snippet I am running
<g:each in="${selectedList}" status="i" var="menuForCity">
<td><input type="checkbox" id="${100+i}" name="check_list" value="${city.id}" checked="checked" /></td>
<g:select name="myClass.id"
from="${instances}"
onchange="${remoteFunction(
controller:'cityPlan',
action:'test',
params:'\'id=\'+this.value+\'\'&cityid=\'+document.getElementById(100+i).value',
update:(i+1))}"
optionKey="id" />
...
Problem I am running into is how to get id of dynamic checkbox thats created in the form ?
Is there any way I can write/evaluate gstring ?
...
params:'\'id=\'+this.value+\'\'&cityid=\''+city.id,
update:(i+1))}"
optionKey="id" />
...
I'm not answering your question but there's an extra single quote in your code that shouldn't be there in the first place, that might solve your problem.
params:'\'id=\'+this.value+\'\'&cityid=\'+document.getElementById(100+i).value',
should be:
params:'\'id=\'+this.value+\'&cityid=\'+document.getElementById(100+i).value',
Related
I'm stumped by this problem. I'm trying to display a class if a certain string is equals to the logged in username. However it doesn't seem to ever evaluate to true.
Here's the code in gsp
<g:if test="${it.from.username == sec.loggedInUserInfo(field: 'username')}">
<div class="direct-chat-msg right">
</g:if>
<g:else>
<div class="direct-chat-msg">
</g:else>
I also tried using this method
<div class="direct-chat-msg ${(it.from.username == sec.loggedInUserInfo(field: 'username')) ? 'right' : ''}">
However nothing I do can get the 'right' class to show up in the div.
Just for good measure, I printed out the values of both classes in my gsp in hidden fields.
<input type="hidden" value="${it.from.username}"/>
<input type="hidden" value="${sec.loggedInUserInfo(field: 'username')}"/>
And the values are exactly the same
<input type="hidden" value="u***#gmail.com">
<input type="hidden" value="u***#gmail.com">
I've tried several combinations of string comparison
.equals(), calling .toString() on both, also trying as String. however nothing seems to be working.
What could the issue be?
I have tried passing the logged in user object in the Model from the controller, and just calling loggedInUser.username and it works. So my question now is, what kind of object is returned by spring security?
The result of sec.loggedInUserInfo(field: 'username')} is an HTML encoded string. Spring security calls encodeAsHTML() before returning 'username' value. Visually they look the same but are they equal? Apparently not!
I have this:
<input id="fileupload" type="file" name="files[]" data-url="rest/controller/upload" multiple>
and I need to make it work in a Thymeleaf template. I have the data-url part figured out but I keep getting an error on the word "multiple". This is needed to allow multiple selection in the file selection window.
I have looked everywhere and have not come across an answer.
EDIT:
If you are not familiar, here is the "multiple" attribute.
http://www.w3schools.com/tags/att_input_multiple.asp
The Standard Dialect of Thymeleaf includes attributes that allow you to set these attributes by evaluating a condition, so that if evaluated to true, the attribute will be set to its fixed value, and if evaluated to false, the attribute will not be set:
e.g for checkedattribute:
<input type="checkbox" name="active" th:checked="${user.active}" />
you have to use:
th:multiple
e.g
<input id="fileupload" type="file" name="files[]" th:multiple="{condition}">
see a tutorial here.
I was working on a webbot and I came across this strange page where multiple variables had the same name but different values in as shown by the Firefox web console. I am not sure as to how I can replicate this behavior in python. Currently, I am using the requests library to make post requests and that takes in a dictionary of name and value pairs. And of course, dictionaries have unique keys. So I was wondering if anyone could tell me how to send post requests with multiple variables carrying the same name.
sel_subj:dummy
sel_subj:ECE
Thanks,
Rajiv
Edit: Here is the html source that causes this
<input type="hidden" value="dummy" name="rsts"></input>
<input type="hidden" value="dummy" name="crn"></input><br></br>
<input type="hidden" value="120138" name="term_in"></input>
**<input type="hidden" value="dummy" name="sel_subj"></input>**
<input type="hidden" value="dummy" name="sel_day"></input>
<input type="hidden" value="dummy" name="sel_schd"></input>
<input type="hidden" value="dummy" name="sel_insm"></input>
<input type="hidden" value="dummy" name="sel_camp"></input>
<input type="hidden" value="dummy" name="sel_levl"></input>
<input type="hidden" value="dummy" name="sel_sess"></input>
<input type="hidden" value="dummy" name="sel_instr"></input>
<input type="hidden" value="dummy" name="sel_ptrm"></input>
<input type="hidden" value="dummy" name="sel_attr"></input>
<table class="dataentrytable" summary="Table is used to present the course search criteria">
<tbody>
<tr>
<td class="delabel" scope="row"> … </td>
<td class="dedefault" colspan="37">
**<select id="subj_id" multiple="" size="10" name="sel_subj"> …
</select>**
</td>
</tr>
</tbody>
</table>
Notice how the select tag and the highlighted input tag have the same name.
The only method that I know is using a variable-name appended with [].
<input type="hidden" value="dummy" name="sel_subj[]"></input>
<input type="hidden" value="ECE" name="sel_subj[]"></input>
This results in an array placed in $_POST['sel_subj'], with $_POST['sel_subj'][0] being "dummy" and $_POST['sel_subj'] being ECE.
Now as I think of it, I think the creation of the array is done by the php-parser when there is a [] attached. This suggests that both values are send through the POST even if there is not [] at the end of the name. Maybe PHP can be configured not to dismiss this values.
In case of GET variables (in the url), you can have multiple values with the same name. You can just parse the entire url and read and use every value.
PHP even solves this automatically if you add [] to the name of the parameter. In that case, it automatically changes it into an array. But this is a trick as well. It is fairly easy to write a piece of code that does the same thing with duplicate names without them having [] as a postfix.
They same will happen post variables as well. You just might need a little more code to read them properly.
The code in this case probably checks if there is sel_subj with any value other than dummy. If that is the case, then that value is used. If it doesn't exists, sel_subj may still exist with the value dummy. That is probably an indication for the script that the form was posted, but no value was selected.
So actually, I think it's quite easy to explain how this script works, and probably even why, but I don't think it's a very good solution to put all defaults in hidden fields this way, so I would suggest you don't try to replicate this solution. :-)
I have a form where you can select something from a selector and click and image this then fires to a controller. The problem is currently the images are submit buttons which i can send params with so i dont know which image has been clicked. my current code it as follows:
<g:form controller="profile" action='postFromAlbum'>
<g:select name="child" from="${names}" value="" noSelection="['':'All Children']"/> <br
<g:each in="${pictures}">
<g:submitButton name="submit" class="image3" type="image" src="${it.urlThumb}" alt="no Picture"></g:submitButton>
</g:each>
</g:form>
does anyone know a better way or know of a way to get around this?
One way is to create an analog of actionSubmit that will support params, like in this question.
Another hacky way is to set an invisible text/radio field and set its value in button's onclick.
I have been reading a lot about this razor thing, and some examples present something like the following:
<input type="text" name="title" value="#Model.Title" />
I would like to do the same on my ASPX view. But no matter what I try, it just won't work. In other words, writing the following :
<input type="text" name="title" value="<%: Model.Title %>" />
Gave me a view with 2 text box, instead of what i'm trying to do. I don't want to use the HTML Helpers as they wont solve my problem. (which is to return a value from the view that is not included on my model).
If the value is in your view and not in your model then do not reference the model. Just reference the variable name you assigned to the value in your view.
<input type="text" name="title" value="#VariableName" />