Derek Organ
Derek Organ

Reputation: 8473

Create editable new rows to a table

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.

Upvotes: 0

Views: 549

Answers (3)

levik
levik

Reputation: 117499

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.

Upvotes: 0

Dave
Dave

Reputation: 88

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)

Upvotes: 1

cgp
cgp

Reputation: 41381

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.

Upvotes: 0

Related Questions