views:

221

answers:

3

I'm trying to add details to a database by using ajax and table dynamic rows.

e.g.

----

{Customer: dropdown menu} | {Description: textarea} | delete

Add New Customer

---

When the user clicks it shows the drop down menu of all available customers. when you click away it just shows the select customer name (not the dropdown menu)

Similarly with the description i want on click to allow them to edit the description of the text area but when you click away it only shows the text you just entered. (not the text area outline)

Add new customer button creates a new empty row.

What libraries or examples can help me get started with this?

I saw this recently in an application recently. In this application it was possible to add new items/rows via ajax and dynamic HTML.

A: 

Use jQuery.

Use the tokenizing autocomplete plugin for jQuery

For the inplace edit use Jeditable.

I'd stay away from drop downs, they are almost always bad design, whether in a menu or selecting from a long list of options. For something like a list of customers which is hopefully likely to be long it is an awful choice of a UI component.

The only time that it really makes sense to use a drop down is when the list of options is short and well known. So for it to be acceptable it probably has to be a list of options which rarely if ever changes, is less than 10 or so items long, and is used frequently (so it is well known). Drop downs are painful.

altCognito
Thanks, I'd rather do the dropdown to stop any errors with text not matching. they don't have rights to create new "customers"
Derek Organ
I changed it to the tokenzing autocomplete. This avoids the issue of them entering items that do not exist. You can display an error or otherwise control what ends up tokenized.
altCognito
Note, you may need to modify how many can be selected.
altCognito
Thanks for the links. regarding autocomplete i still want to use dropdown.. in some cases the user won't even know the first letter.. they will need to see the list as to choose the correct one.
Derek Organ
Errr... If they don't know the first letter, how will they find them in a drop down?
altCognito
This is the way I want to do it. For what I'm doing it is the best way and to explain it would be outside the scope of my question. I'm asking how I can do it.To answer your question.. It is a list managed by an Administrator.. The user gets no notifications of new items to the list but they still need to choose the item that is most relevant. The keyword here is 'relevant'. It's not a precise answer every time. therefore => showing the list is important.
Derek Organ
+1  A: 

You should be able to do that easily enough using jQuery (look at the selectors, events & manipulation in their docs). For example, for the dropdown

<span id="customer-name"></span>
<select name="customer-list" id="customer-list">
 <option class="name" value="cust-1">Frank Frankson</option>
 <option class="name" value="cust-2">John Johnson</option>
</select>

And the jQuery :

$('.name').click(function(){     
 $('#customer-name').text($(this).text());
 $('#customer-list').hide();
});

In that function you could do something with the option element value if needed (an ajax post or whatever).

The principal for changing the Text Area description would be the same (you could grab the text out of the textarea, add it to a div & hide the textarea; if they need to edit again, just show the textarea & hide the div)

Dave
Cheers dave, yes this is what i'm thinking myself but was looking to see if there were any good example code out there i could work off with editable rows the way i describe.
Derek Organ
A: 

Most sites where you see such functionality accomplish it with styling - you can style a text input box to look like plain text (by removing the border and setting the background color to transparent). When the input is clicked on (focused), the style changes:

<style>
   .blurredText { border: none; background-color: transparent; }
</style>
. . .
<input type="text" class="blurredText" value="Click me to edit"
    onfocus="this.className=''" 
    onblur="this.className='blurredText'"/>

Styling a select the same way may prove difficult however, since select controls are notoriously resistant to CSS. You can still use the method Dave proposed.

levik