Coldfusion 9 - Checkbox values from form to replace parameter value/s - loops

Very new to coldfusion. So I have a a form outputs values from DB into checkboxes.
<cfoutput query="Offices">
<label><input type="checkbox" value="#offices#" name="Offices">#offices#</label>
</cfoutput>
and when a user selects more than one checkbox it passes multiple parameters into URL which looks like this:
offices.cfm?Offices=A&Offices=B&Offices=C
I am trying to prevent multiple of the same parameters being passed so I want it to return like:
offices.cfm?Offices=A,B,C&...
I am really struggling to figure this out. Help is appreciated.

(Summary from comments, just to close out this thread ...)
True, but that is just how the parameters are transmitted in the url. Per the html specs, when using method GET, the browser builds a builds a big string of name/value pairs for all (successful) form fields. Then appends them to the url as the query string:
Submit the encoded form data set
If the method is "get" and the action is an HTTP URI, the user agent takes the value of action, appends a ? to it,
then appends the form data set, encoded using the "application/x-www-form-urlencoded" content type.
form data set
A form data set is a sequence of control-name/current-value pairs constructed from successful controls
However, it does not matter that the field name appears multiple times in the URL. If you dump the #URL# scope, you will see that CF has already parsed those values into a single CSV list for you. That list can be accessed using the variable name URL.Offices.

Related

How to display server side validations for individual input fields when using AngularJS and Springboot?

so my question is if this is possible to display the errors on top of individual input fields when using AngularJS service to call Rest controller, because when response is received from AngularJS service, it comes as a single error message, so either that whole errors will be displayed on UI.
For example we are validating field A, B and C using server side validation, and there are 3 types of error messages coming from server but as a single string.
It depends on the return type of your method. If return type is string then it will return as single string. Please use class object concept or dynamic json object in var type variable or use pipe ("|") separator and split it to show on page.

multi-select dropdown and form field shows as array?

I am using ColdFusion 2016. I have a form with a multi-select drop down. The name attribute of the field is called jobRoleId. When I submit this form the field name is available in the form scope as jobRoleId[]. How do I get the value of this field? The name comes across like an array but I can't seem to just dump out the value due to the brackets.
I've tried dumping out the value, but I get an error. I feel like I have done this in the past and the form field name didn't contain the brackets [] after the field name when using a multi select menu:
<select id="jobRoleId" name="jobRoleId" multiple="multiple">...</select>
Is there a way to somehow have the form field name just come across as jobRoleId?
writedump(jobRoleId[]);
abort;
When I execute your code I get a comma separated list for the values of jobRoleId. Are you using any CF frameworks?
My output:
I also suggest looking at the client side JavaScript to confirm there's nothing changing the submitted name. You can use the Chrome/Firefox/IE debugger to watch your submissions and confirm what is being submitted
Multi select lists, in CF, should return a list of values, as far as I remember...

Can I set a parameter using ngRoute?

I am making an app that shows a list of items, and that list can then be refined by multiple filters. If I were to fetch a list of those options from the URL string, then that would allow visitors to share (or bookmark) a link that takes you to a filtered list of data. But my questions is how would I write those options to the URL string?
So the idea is that once a select element has been changed, to refine the results. Let's say for example that it's just the order of the items.
<select ng-model="order" ng-change="changeOrder()">
<option ng-repeat="['date', 'amplitude', 'name'] as option">{{ option }}</option>
</select>
I would want to write that option into the URL string, so that it now contains (if you've selected amplitude) ?order=amplitude. Now, if you refresh the page, the data can easily be sorted by amplitude again.
But when there is a lot of those filters and sorting options, and they can be both set or reset to default, it becomes rather difficult to put those options all together, to check if an option is already in the string so as to not have it twice, and whether to add it behind a ? if there are no other options, or a & if there are other options already defined.
So in other words, what I want to know is does ngRoute provide methods to set parameters; not just read them? So I could do something like $routeParams.set("order", "amplitude").
If you want to change the URL, you should do this through the $location service.
Specifically the $location.search(search, paramValue) will allow you to change the query string values.
I made a plunk that demonstrates both using HTML5 mode and changing the $location using these functions. It can be found here. In order to see the URL change, click the pop-out button .
You don't have to do the string parsing yourself. AngularJS will also allow you (with the same function) to query the currently set parameters. So it's a matter of querying all the URL values, changing the one for which filter you're changing, and then setting the values back.
This is what the second button in the example demonstrates. Even though the first button will only set its own value (and remove the others), the second button will keep all other items as well.
The relevant code:
var values = $location.search();
values.orderThatsUpdating = newOrderValue;
$location.search(values);

How do i get my id field to show up in the request data when updating multiple records?

Datasource: Array source (Open source code)
I have a __getTable method that loads the data from a configuration file to an array that looks like this:
I created a method that takes in data in this form and creates a table out of it. The table creates a column in the row for every field present in the given data array except for id. id is a hidden field and the code generated by the input function looks like this:
but shows up like this when inspecting the code in firebug:
Ignore all except for what is in the control-group division.
Since im using the array source, i create my own update method and have to call updateAll() in my controller to call the method. All the data i need is in the request data except for the id! why, and how can i fix this? It looks like this:
The rest of the information on here might not be necessary but ill post it just in case.
I found the problem. Most of it was unique to my code though. There was a bug where i call the $this->Widget->input function. I use index rather than the id and that screws up my tabs. each data array passed in to the function had indexs from 0-~11 and so the values were overriding each other since the submit was for multiple tabs. Also i have a function 'open' that opens a table and the rows were specified to have 4 columns rather than 5 and id was the 5th column.

how retrieve only selected checkbox values in action class in struts 1.3

i am new struts i am developing web application in which i have a requirement that i have to show records in tabular format i have made use of display tag in struts with every record i have a checkbox now i need to retrieve the values of those checkboxes in my Action which are checked . but what i am receiving in Action array of all the checkboxes. actually while displaying checkboxes by making use of display tag all checkbobes have got same name therefore i am not understanding how handle this care i have searched on google but did not find suitable situation
<display:column title="Service">
<input type="checkbox" name="sercive" />
</display:column>
how to handle this situation not understanding .could anyone give some sample code
or hint to handle this situation
I am not sure about display tag.
But in struts you have to define a property in Form bean (i.e. ActionForm) of type String[] or List with the name same as defined for your check boxes.
Then in Action class you will get the array of selected checkboxes only.
If this is not working. Then you can try of getting the values using request.getParameter("service"). This will return comma separated list of selected checkboxes which you can convert to array using split() method and then you can continue with your logic.
I hope this helps you.
Plain HTML checkboxes are only submitted if they're checked, that's just how clients work.
You must provide a differentiating factor, generally a value (e.g., a service ID in your case), to determine which has been selected. Your action form would contain a collection of those IDs.

Resources