Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input text box not editable with jQuery Draggable?

I call a javascript function that dynamically builds <li>'s with a text input box and drop down inside. The drop down works fine with jQuery's Draggable but I cannot edit the input text box?

function addField(type){
  var html = '';
  html += '<li class="ui-state-default">';
  if(type == 'text'){
   html += '<b>Text Field</b><br />';
   html += 'Field Name: <input type="text" name="text" id="text">&nbsp;&nbsp;&nbsp;';
   html += 'Field Size: <select name="textSize" id="textSize' + fRank + '"><option value="small">Small</option><option selected value="medium">Medium</option><option value="large">Large</option><option value="large2">Large 2 Lines</option><option value="large3">Large 3 Lines</option><option value="large4">Large 4 Lines</option></select>';
  }
  html += '</li>';
  $("#sortableFields").append(html);

  $(function() {
       $( "#sortableFields" ).sortable({
      revert: true
    });
    $( "#draggable" ).draggable({
           connectToSortable: "#sortableFields",
    helper: "clone",
    revert: "invalid",
    cancel: ':input,option'
    });
    $( "ul, li" ).disableSelection();  
             });
}

I have played around with the cancel option but it doesn't help.

What do you suggest?

like image 355
Mitchell Guimont Avatar asked Oct 04 '10 20:10

Mitchell Guimont


People also ask

How do I make a textbox non editable in jQuery?

$('input[type="text"], textarea'). attr('readonly','readonly');

How do you make something draggable in jQuery?

Using jQuery UI, we can make the DOM(Document Object Model) elements to drag anywhere within the view port. This can be done by clicking on the draggable object by mouse and dragging it anywhere within the view port. If the value of this option is set to false, it will prevent the DOM elements to be dragged .


1 Answers

I think the problem is with your use of .disableSelection() for the <li> elements. Instead of doing that, put the text (stuff outside your <input>) into <span> elements, and then disable the spans

$('li > span').disableSelection();
like image 170
Pointy Avatar answered Nov 15 '22 17:11

Pointy