Form variable populated in request, but empty string on receiving form - coldfusion

Something weird or something obvious.
I've inherited a coldfusion application, which I need to work with as it is for the meantime, including the widespread use of <CFFORM> etc.
We have a select list as follows:
<cfselect
class="selGroup"
query="get_merchant_categories"
name="category_id"
display="category_name"
value="unique_id"
onclick="document.getElementById('Merchant_Groups_Form').submit();"
size="15">
</cfselect>
This produces the following in the DOM:
<select name="category_id" id="category_id" class="selGroup" onclick="document.getElementById('Merchant_Groups_Form').submit();" size="15">
<option value="1">Equestrian Sports</option>
<option value="2">Other</option>
</select>
and the following page output:
Upon clicking the first item in the select list (Equestrian Sports), the request is seen as follows (NOTE: CSRFTOKEN is a hidden form field):
And the dump at the top of the receiving page is:
So, all is good there.
HOWEVER, when I click the second item in the list ("Other"), the request is OK and looks like this:
But, the dump on the receiving page looks like this:
Been trying to figure this out for over an hour and have no idea what is going on. Maybe someone's come across this before.

Related

Call function through livewire with the value of a custom data-attribute as a parameter

I have a select input which, using livewire, calls a function whenever the selection changes. According to the documentation you can use $event.target.value to get to the selected value, however I want to send a different attribute value (myvalue) to my function.
<!-- this doesnt work -->
<select wire:onchange="myfunction($event.target.dataset.myvalue)">
<option value="1" data-myvalue="12345">
</select>
I got it working using Alpine.js but it seems odd that I need another framework to do so.
<!-- this does work, but requires alpine.js -->
<select x-data='{}' #change="$wire.call('myfunction',$el.options[$el.selectedIndex].dataset.myvalue)">
<option value="1" data-myvalue="12345">
</select>
Is there a pure livewire solution to this?
Your first code snippet is practically there already. The documentation you linked, in which $event is described, even shows why your code snippet doesn't work:
Your code uses wire:onchange, but Livewire checks for wire:change.
With your example though, you could also use wire:model="foo" and hook into the updatedFoo($newValue) function.
See the lifecycle hooks doc

Obtaining selected item in dynamic radio button

I have got radio button like this:
<span><input onClick="if (EventHandlers.valueChanged(event, this)==false) return false;" class="radio"
label="Temp label" type="radio"
id="TempId_01" onblur="EventHandlers.onBlur(event)"
name="TempId"
value="01" delayOnChange="true" checked></input></span>
i want to get a value of checked item. I have tried smth like this (by xpath):
//input[#checked and #name="TempId"]/#value
However this not work at all, is it valid?
XPath queries need to return physical DOM elements that Selenium can work with. Selenium is then responsible for grabbing any attributes, details or properties from that element - your query is, by this point, all over and done with.
So, you'll need something like:
driver.findElement(By.xpath("//input[#checked and #name="TempId"]")).getAttribute("value");

Getting dropdown value from template django

I am facing an issue working with django ( using shopcart ). I want to add a select options field to change dynamically an item suscription in the cart, but I am not getting the value selected from the template.
In my template where I display the cart I have :
<form action="" method="GET">{%csrf_token%}
<select name="suscr" title="suscr">
<option value="" selected>Suscribe</option>
<option value="1" name="suscr" >Weekly</option>
<option value="2" name="suscr">Monthly</option>
</select>
</form>
I want to select an option and then, if I press 'Checkout' to have the cart updated.
Appart from that, I believe its missing a method modifying the item in cart.py.
Any ideas would help.
Thanks
The above form is inside a loop
{% for item in cart %}
What i propose you to do is not python-oriented but all javascript for the most part as, from the description, we assume that what you are dealing with is going all at the client-side.
As you are dealing with a shopping cart, what i'd do is storing what the user is checking in a sessionStorage so that the information would persist while the user navigates through your website even with multiple tabs. As the user might just be "walking around" you shopping website, there's no need to push things to the database without even knowing if the user wants that. Just remove the form and keep with the select, then you get what the user selected appending an attribute to select: <select onchange=my_function(this.value)>...</select> and then, inside my_functionin a script change whatever you want to the page.
When the user enters the shopping cart page you show him what he selected so far getting the items from the sessionStorageand then, if he/she confirms that wants to buy, then submit a form to the server-side, update the database and proccess that as your workflow states.
tl;dr: store the options in sessionStorage, just post to the server at the end.
For help on the server-side update your question with more info about the cart.py

Field giving error after CF9 to CF10 Upgrade

We have a form which has some mandatory fields and 2 buttons(One is Submit, second is Search).
Search buttton code is like :
<input name="btnSearch" type="submit" id="Search" value="Search">
This code redirects to action form and then further to a new screen. Finally it reverts back to the main form and has code to restore the selected values.
One of the mandatory fields has the following code:
<td align="right">Class Id:<font color="red">*</font></td>
<td><cfselect name="YY_CLASS_ID" size="1" query="XX_Class_List"
value="XX_CLASS_ID" display="XX_DESCRIPTION"
required="yes"selected="#variables.XX_CLASS_ID#">
<cfif variables.XX_CLASS_ID eq "">
<option value="" selected></option>
</cfif>
</cfselect></td>
When user clicks on the search button and this Class ID dropdown is blank, they get an error that "Error in YY_CLASS_ID text".
yy_class_id field has required attribute as ‘yes’ and message attribute is not set. As per our understanding, this means error should always come if the user tries to navigate away from the screen without populating the CLASS ID.
However, as per our user ,they were not getting this error in CF9 and started coming after the CF10 upgrade. They are frequent users of the screen and could have not missed this in past if this was happening during CF9 days.
Can anyone please confirm if something has changed in CF10 which was not earlier in CF9 and causing this issue. Or we missing something here.
Let me know if any more information is needed.

Django: How can I invisibly pass a variable to another template?

I have three templates in my project—we'll call them first.html, second.html, third.html.
first.html gets a string from the user, using an <input> tag:
<input type="radio" name="selection" value="example_string" />
second.html displays this string using {{selection}}. (In my views.py, I got the value using request.POST.get and render_to_response().)
The question is: how do I send this value from second.html to third.html? One of my attempts—using a <span> tag to save the information in a variable—is illustrated below, but it doesn't seem to work.
<span name="selection" value={{selection}}>{{selection}}</span>
Edit: The following line works by creating a dummy single radio button. I don't know why it shouldn't be possible to create a variable without an <input> tag [visible to the user].
<input type="radio" name="selected" value={{selected}} checked="checked" />
You need to understand how the web works: each page is entirely separate, and is requested using a separate request.
Your basic options are: save data on the client side, or post it back to the server.
Both options can be performed with javascript, or posting back can also be performed by posting the form back to the server.
If you want to send it back to the server, it will have to be stored in the current session, or in a model.
There are many javascript libraries. If you want to use them, I suggest you google around the subject.
Answering my own question, now that I've found the answer on Django's documentation.
There's a special kind of <input> tag precisely for this: "hidden". The following line accomplishes the same as was asked in the question, but without a dummy element visible to the user:
<input type="hidden" name="selected" value={{selected}} />