Ajax Autocomplete field: display one value, but use another? - ajax

I've got an autocompleter in a CakePHP app that provides a dropdown list of neighborhoods to attach to a place. I'm pulling from a table 'neighborhoods' with name and id fields. I want the user to see the name of the neighborhood, and I want the app to see the id of the neighborhood and insert it into the places table. How can I make this happen?

Another way of doing this would be to storing the id. Then when a user presses submit you replace the input field's value with your stored value.

assign the correct (hidden) value to a hidden input field

This type of functionality is normally achieved with a combobox, which is like an autocomplete, with an underlying select elememt, see here

Related

Rails: disable input tag upon selection from a dropdown menu

Scenario/Context
I've got a drop down menu with two input elements underneath.
From the dropdown menu, are names of companies (with values set to the respective company id's), and another prompt to Add a new company.
If the option to Add a new company is selected from the dropdown, then the user is to fill out the 2 input field elements (i.e. company name and company email).
Otherwise, if an available company is selected from the dropdown,
then the 2 input fields (for company name and email are to be disabled).
My question
Is this possible to do without an AJAX call if I want things to happen without a page refresh?
Can anyone suggest some other alternatives??
Many thanks!
That is absolutely possible, though you'd need to use some JavaScript to make it happen and load a bit more data to the DOM on the initial page load.
For each option in your company select dropdown, add a data attribute for the name and email.
Then, watch that dropdown for the change event in JavaScript. Whenever that event is fired, if the data-company-name and data-company-email attributes are defined for the selected option, disable the input fields and populate them with those values. If those data attributes are not defined for the option (likely only for your 'Add a new company' option), then clear the values from the input fields and enable them.

How do I link two fields to the same table in ServiceNow?

Forgive my ignorance for the proper terminology, but let me try to explain what I want to happen.
I have two custom fields on the incident table/form. I have created a custom table with 2 columns. I have figured out how to reference the table in one of the fields, allowing me to search the entries. Now I want to link the field selection to the other field via the custom table I made. When I make a selection in field A, I want field B to populate with the other column on the same row Field A pulled from in the first place. How would I do that?
Sounds like you want what's commonly referred to as a "derived field" or a dot-walked field.
You have a reference field which stores the reference to the other table, and want a second field on the form that shows another field on that referenced table. You don't actually need to create a new element, you just need to add a dot-walked form element.
Once you have the reference field added, go to Personalize/Configure the form layout.
In the slushbucket of available fields, you'll notice that reference
fields show up in green text with a little [+] next to them.
Select your reference field and a little button will show up between the two
lists, just above the "Add" button
Click that button and the left-side available fields will show the fields available on that reference field's table.
From here, select that second field that you want to display on your form, and bring it over to the right side where you want it.

Show hidden data with mouseover in a particular colum of Jqgrid

how can display items of a hidden colmodel when mouse over another column which shows only some part of the data. in user column i have many names, i only display first user name and rest the count. so i passed the full names as hidden. I want to display that names according to the mouseover
If I correctly understand the problem you can solve it by usage cellattr callback which defines title attribute based on the value of another (hidden) column. See the answer for the corresponding code example.

Filling dependent drop downs with ajax, need to set selected value to person's db value

I have a form where the location fields use a dependent drop down set up, if you choose united states as your country the state dropdown will appear. The fields are populated through an ajax call when fired so it's not loading every single country, state or province, and city in the world on page load lol.
It all works great, however the problem I'm running into is how to set the default selected value from what's already saved. It has to prepopulate those values otherwise if the member doesn't change the location fields every time he edits his profile the location fields will be blank.
I sort of got around the issue by simply doing a query select and then adding the value on top of the ajax pulled values, but this is a really cheesy way to doing it and doesn't work very well.
I need to find a way to set the selected value from the ajax results. I'm sure it can be done by somehow defining the selected value in the code but I'm not exactly sure on how to go about it.
You can find the selected value from db and use
<option selected value="<selected_value>">data</option>
while populating the data from ajax call..

Showing date from two rows in table view, respectively in two text fields, via binding

I have a class named as transaction in which one attribute is transactionDate which is of type NSDate.
I am using NSArrayController to display a list of transactions in a table view.
My requirement is-
I want to show date in first row in a
text field labeled as "From" and date
in last row in a text field labeled as
"To".
My questions is-
Can I achieve this via binding in IB?
If yes then how?
Thanks,
Miraaj
Yes, you can do this (or something like it), see the #min and #max array operators.
Here's how to do a very simple version of this:
Open Interface Builder - create a new application
Add an NSArrayController, set it to automatically prepare content.
Add a Table, label the two columns "name" and "age"
Add a Button (labelled "+") and two Labels (change name to maxval, minval)
Wire up the NSArrayController bindings as follows:
Here's the application running (just in interface builder "simulate" mode). To use it, click + then click on the top row of the table and put a name in the first column and an age in the second. Then repeat for a few more people.
This all looks a bit cryptic, but it is sufficient. I added the labels "Max Age" and "Min Age" for clarity in my version.
Unfortunately this is not something Bindings is particularly good at. You could achieve it but it would be very hacky.
The NSTableViewDataSource protocol is still a perfectly relevant and valid way to provide data to a table. In cases like these (where you're not just presenting a straight-vanilla set of uniform data to a table) the data source protocol is the only sane way to solve the problem. This way you're in complete control of what the table displays.
The only "hard" part is that, if you're using Core Data, your data source class will need to observe the Managed Object Context for changes and reload the data (either -reloadData to refresh the whole table or use -reloadDataForRowIndexes:columnIndexes: to cherry pick the rows you want to refresh).

Resources