I have a page that has around 30 different entry fields, one of the top fields is a textfield and after this is filled in, I want to populate a dropdown and a textfield. I currently have it calling a javascript function, however my main problem is that I need to query the database to find out what value to populate the fields with.
Here is the type of thing I was trying to do:
function populateState(){
<cfquery name="getState" datasource="#application.dsn#">
SELECT STATE_CODE, CODE_ID
FROM LERG_LATA_V1 LEFT OUTER JOIN Code ON STATE_CODE = CHAR1_TX
WHERE NPX = #NPANXX#
</cfquery>
}
And then after that I would need to read the result and select that element. Any suggestions on how to do this? Most of what I am finding on my google searches are saying you cannot mix cf and js since they execute at different times.
You need to either create a state JavaScript array with your query, and then reference that in your javascript, or use the built-in cfselect tag binding to make this happen. Here's a simple example of how I do this:
http://www.dansshorts.com/post/cfselect-binding-and-selectedvalues
Dan
Related
Its relatively trivial in Sqlite to do a select with multiple where clauses. However I am simply stumped to find a way to do multiple where clauses where any of the parameters can be null. Basically I have a multi drop-down screen where the query is generated on the fly based on the selections made on each of the dropdowns. It works fine when there are values in the parameters but it doesnt work when some of the dropdowns are left blank.
My select query is like this:
tx.executeSql('SELECT * FROM tableOne WHERE id=?, name=?, address=?', [id, name, addredd], records);
Any ideas ?
You have to dynamically construct where clause based on selection
or
you can use like operator instead of where, passing empty strings instead of NULL values.
After marking in a visualization i want to capture a particular column value form rows marked and display it in text area .
thanks
The way to do this is to add a data function to the analysis. Define the function as a identity function, i.e.:
output <- input
This can be an R function or TERR function. If you use TERR it can execute locally rather than going to stat services (though web player will need to use stat services anyway).
Now, connect the data function to your analysis and as input you make it depend on the current marking. Assign a value to the input parameter by creating an aggregation on the column with the value you are looking to collect.
Assign the output of the data function to a document property.
The image linked here shows a sample of how to configure the input parameter:
Sample input parameter config
To show the result in the text area you create a normal property control of your choice in the text area, and attach it to the document property that is written to by the R/TERR script.
When using the .each function with JQuery like below is there anyway to automatically group the results by type to save some time;
$(selector).each(function () {
//do stuff here for each found
});
The above will obviously go through each found element one by one but with the logic within my code I'm just detecting what field type the field is and I would action each field type to do the same thing. I'm just trying to save doing all the logic for the same field type over and over again.
To detail a little more, I have a value and it needs to go into may different fields types. Simple text fields are fine as they're just insert in using .val() but for other default and custom fields that I have such as picklists and multi-select boxes I need to do some logic around the value for these fields so the appropriate values are set, but not all these type fields don't exist so don't want to do the necessary logic beforehand if those fields don't actually exist. So if I had 50 picklist fields I would obviously only want to do that logic once and set the values for all picklist fields to this value(s) that the logic had set. I just thought they're might be a simple method of JQuery that I'm missing here?!
You can do some manual testing and run your code a different way
var all = $(selector),
text = all.filter('[type="text"]'),
select = all.filter('select');
text.val(someValue);
if (select.length){ // select elements exist
// do logic and apply to all
select.val(selectSpecificValue);
}
Currently I have Select2 in my application, and have previously implemented ajax calls to the database to get a smaller subset based on search query entered by a user.
However, users want to be able to click the back arrow on the browser, and have the query automatically run again (something that currently does not happen with Select2). I was able to implement this by pulling the entire dataset (over 18,000 elements) in and calling select2 on that.
The problem with this is that Select2 basically does a foreach in a foreach when doing a search (foreach element in the dataset, go through each string and get the index of the query - which I understand is basically breaking the string into a char array and checking each char individually to see if the combination is found). So every time someone types a character, we're looking at over 18,000 operations, even though the majority of elements are eliminated as options.
Is there a way to make Select2 actually eliminate the options that don't match (create and bind to a temp array or something like that) or perform a binary search instead of a linear search? If not, are there any alternatives to Select2 that DO implement binary search instead of linear search, or would I need to create my own jQuery plugin to do this?
In this jsfiddle1 a hidden select element is used and a clone of that to filter input. The filtering is done with:
for (var i = 0; i < that.selector.options.length; i++) {
if (re.test(that.selector.options[i].text)) {
sclone.add(new Option(that.selector.options[i].text, i));
}
}
Where re is a RegExp created from an input field that placed above the select clone.
Maybe that's an idea to play with?
1 The language used in the first selector is dutch, but I suppose that shouldn't be obstructive to the idea.
( i am using the backbone forms extension to create my forms: https://github.com/powmedia/backbone-forms)
I have two select boxes and when the first is changed it should change the values of the second. I have got the filtering sorted and have an array of objects that need to be used as the new values for the second select box, i have placed these in a new collection.
After ready the documentation i assumed i could do this:
var newProducts = new App.Collections.Products(correct);
form.setValue({ ProductUsed : newProducts});
Where correct is an array of objects, however my select box just goes blank and allows me to select the other options when focused.
Any advice would be great?
Cheers,
Tom
evilcelery shared this fiddle: jsfiddle.net/evilcelery/c5QHr
This resolves the issue i had.