0

私はSymfony2Frameworkを使用していますが、これが私がやりたいことです。

入力タイプの値を変更したいのですが、selectableで選択した値にしたいと思います。

jquery.comの例では、選択したフィールドがありますが、フォームデータとしてコントローラーに送信できるように、非表示のフィールドに配置する必要があります。

JQueryドキュメントの例を読みましたが、変更に問題があります。

$(function() {
    $( "#selectable" ).selectable({
        stop: function() {
            var result = $( "#select-result" ).empty();
        $( ".ui-selected", this ).each(function() {
            var index = $( "#selectable li" ).index( this );
            result.append( " #" + ( index + 1 ) );          
            });
         }

    });
});

そして私はこの隠されたフィールドを持っています

<input name="horario" type="hidden" value=" " />

入力フィールドの値を変更したいのですが、たとえば次のようになります。

選択しました

#1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #16 #17 #18 #19 #20 #21 #22 #23.
4

2 に答える 2

1

このようなもの:jsFiddleの例。これにより、選択したアイテムに非表示フィールドの値が設定され、デモの目的で、アラートでそれらが表示されます。

jQuery

$("#selectable").selectable({
    stop: function() {
        var items = '';
        var result = $("#select-result").empty();
        $(".ui-selected", this).each(function() {
            var index = $("#selectable li").index(this);
            items += (" #" + (index + 1));
        });
        alert('You have selected: ' + items);
        $('input[name="horario"]').val(items);
    }
});​

HTML

<input name="horario" type="hidden" value=" " />
<ol id="selectable">
    <li class="ui-widget-content">Item 1</li>
    <li class="ui-widget-content">Item 2</li>
    <li class="ui-widget-content">Item 3</li>
    <li class="ui-widget-content">Item 4</li>
    <li class="ui-widget-content">Item 5</li>
    <li class="ui-widget-content">Item 6</li>
    <li class="ui-widget-content">Item 7</li>
</ol>

</ p>

于 2012-03-02T21:57:52.240 に答える
1

簡単だ。javascriptを使用してリストデータを取得できます。

$(function() {
  $( "#selectable" ).selectable({
    stop: function() {
        var result = $( "#select-result" ).empty();
    $( ".ui-selected", this ).each(function() {
        var value = this.innerHTML;
        result.append(value+" , ");          
        });
     }

});

});

于 2014-03-12T12:04:56.797 に答える