fix error

This commit is contained in:
chiu 2020-01-19 22:29:30 +08:00
parent d96c51168e
commit dc84a8e7a3
2 changed files with 38 additions and 8 deletions

View File

@ -14,7 +14,7 @@
<div class="control-group"> <div class="control-group">
<label class="control-label muted" for="key_0">Key</label> <label class="control-label muted" for="key_0">Key</label>
<div class="controls"> <div class="controls">
<%= f.text_field :key %> <%= f.number_field :key, :autocomplete => "off", :'data-type' => 'key' %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">

View File

@ -100,13 +100,43 @@
label.addClass("hide"); label.addClass("hide");
} }
}) })
function key_on_blur() {
$('input[data-type=key]').on('blur',function() {
var index_this = $(this).parents('.attributes').index()
console.log(index_this)
var input_this = parseInt($(this).val()) - 1
if (input_this > ($('#attributes-area>.attributes').length-1)){
input_this = $('#attributes-area>.attributes').length-1
}else if (input_this < 0){
input_this = 0
}
if (index_this > input_this){
$(this).parents('#attributes-area>.attributes').insertBefore($('#attributes-area>.attributes').eq(input_this))
}
else if (index_this < input_this){
$(this).parents('#attributes-area>.attributes').insertAfter($('#attributes-area>.attributes').eq(input_this))
}
update_key(this)
});
}
$("#attributes-area").sortable({ function update_key(ele){
update: function( event, ui ) { var ui_child=$(ele).parents('#attributes-area').find('.attributes');
updateOrder(); for (var i=0;i<ui_child.length;i++){
} var now_ele = ui_child.eq(i);
}); now_ele.find('input[data-type=key]').val(i+1);
}
updateOrder
}
$('#attributes-area').ready(function(){
$("#attributes-area").sortable({
update: function( event, ui ) {
update_key($(ui.item[0]).find('input[data-type=key]'))
}
});
$("#attributes-area").on('change',key_on_blur)
key_on_blur()
})
var updateOrder = function(){ var updateOrder = function(){
var attributes = $("#attributes-area").find(".attributes:visible"); var attributes = $("#attributes-area").find(".attributes:visible");
attributes.each(function(i){ attributes.each(function(i){