I have a list which can be sortable. I'm using jQuery UI with widget, mouse, position, sortable addons.
CSS:
#sortable{
width : 550px;
display: inline-block;
}
#sortable li, #add {
width : 550px;
margin : 5px;
padding : 5px;
height : 50px;
}
#sortable li img.social-icon, #sortable li img.drag-cursor {
width: 40px;
height : 40px;
float : left;
}
#sortable li img.social-icon {
margin-right : 5px;
}
#sortable li img.drag-cursor {
margin-left : 5px;
cursor : move;
}
#sortable li input {
height:40px;
width:450px;
line-height: 45px;
float:left;
}
#add {
cursor : pointer;
text-align: center;
line-height: 45px;
}
.ui-state-highlight { height: 50px; line-height: 50px; }
HTML:
<div id="dash-wrapper">
<ul id="sortable">
<li class="ui-state-default">
<img src="images/social/twitter.png" class="social-icon" />
<input type="text" value="textt" name="user-media-link[]" class="user-media-link">
<input type="hidden" name="social-media-type" value="1">
<img src="images/drag.png" class="drag-cursor">
</li>
<li class="ui-state-default">
<img src="images/social/facebook.png" class="social-icon" />
<input type="text" value="textt" name="user-media-link[]">
<input type="hidden" name="social-media-type" value="1">
<img src="images/drag.png" class="drag-cursor">
</li>
<li class="ui-state-default">
<img src="images/social/rss.png" class="social-icon" />
<input type="text" value="textt" name="user-media-link[]">
<input type="hidden" name="social-media-type" value="1">
<img src="images/drag.png" class="drag-cursor">
</li>
</ul>
<div class="ui-state-default" onCLick="addNewSocial(); return false;" id="add">ADD</div>
</div>
Script:
$(function() {
$("#sortable").sortable({
placeholder: "ui-state-highlight"
});
$("#sortable").disableSelection();
});
function addNewSocial() {
$("#sortable").append('<li class="ui-state-default"><img src="" width="100" height="100" /> <input type="text" value="textt" name="user-media-link[]"><input type="hidden" name="social-media-type" value="1"></li>');
}
It's working very well, but I can't type anything to inputs. I can reach them only via TAB button. When I click them, nothing happens. You can see a live example.
I was read all questions which related with this question, but i couldn't find right answer.
W3 Validation is OK There isn't any error on Firebug Operation System : Ubuntu 11.04 Browser : Firefox
To solve the issue of being unable to type in an input field in React, make sure to use the defaultValue prop instead of value for uncontrolled input fields. Alternatively, set an onChange prop on the field and handle the change event. Here is an example of how the issue occurs.
it is because you are rendering the form in a function inside render(). Every time your state/prop change, the function returns a new form. it caused you to lose focus.
// App. js - Input editable UI import React, { useState } from "react"; import Editable from "./Editable"; function App() { // State for the input const [task, setTask] = useState(""); /* Enclose the input element as the children to the Editable component to make it as inline editable.
This happens because you have $("#sortable").disableSelection();
. Remove it and will work ok.
http://jsfiddle.net/KbBnu/1/
If would like to prevent text selection but continue to use inputs at the same time, you should try this
$('body *').not(':has(input)').not('input').disableSelection();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With