zysyyz / jquery-option-tree

Automatically exported from code.google.com/p/jquery-option-tree
0 stars 0 forks source link

example 6,when re-select change level 3 the value is null #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
in example 6,default

select1        select2     select3       text

Baby&Toddler=>Baby Toys=>Choose level3=>226

when i use select3 to choose some option,then the text change the value,this is 
all right,
but if i re-choose the `Choose level3` option,
then the text value will become `null`
what i expect is `226`,the last select option that has value,and this is 
identical with the state of beginning.

i'm very appreciate you fixed the last i submmit issue quickly.

Original issue reported on code.google.com by FREDERICK.Mao on 2 Nov 2010 at 1:21

GoogleCodeExporter commented 8 years ago
add tried fixed by myself,it seems work for me now,below is my change code,take 
a look,is there some bug on it,hope can merge into the trunk

Original comment by FREDERICK.Mao on 5 Nov 2010 at 7:33

Attachments:

GoogleCodeExporter commented 8 years ago
this tried replace name to id as selector,then it can support a product belongs 
many categoreis situation,i give a picture in attachment of my use case, 

all the text type has the same name but differnet id,so it can used by 
jquery-option-tree and also could suit for server-side receive all values of 
text type in a array type

Original comment by FREDERICK.Mao on 5 Nov 2010 at 1:06

Attachments:

GoogleCodeExporter commented 8 years ago
Just to be clear, so your diff works correctly for your use case and you didn't 
find any side effects?

Original comment by kkotowicz on 5 Nov 2010 at 1:59

GoogleCodeExporter commented 8 years ago
i add a switch set_value_on_last_no_empty_value:false,if set true and the last 
leaf select is `choose level x`,then it will tried find parent select value to 
the result text input.

but there still have side effects: i changed selector by 'name' to by 'id' 
so the demo6 like bellow,i change the selector use #demo6

<div>
<input type="text" id="demo6" />
</div>
<div class="results" id="demo6-result"></div>
<script type="text/javascript">
$(function() {

    var options = {
            empty_value: 'null',
            indexed: true,  // the data in tree is indexed by values (ids), not by labels
            on_each_change: 'get-subtree.php', // this file will be called with 'id' parameter, JSON data must be returned
            set_value_on: 'each', // we will change input value when every select box changes
            choose: function(level) {
                return 'Choose level ' + level;
            },
            preselect: {'demo6': ['220','226']}, // array of default values - if on any level option value will be in this list, it will be selected
                                                                        // be careful of variable types - '111' !== 111
            preselect_only_once: true // prevent auto selecting whole branch when user maniputales one of branch levels
            set_value_on_last_no_empty_value:true,//default is false,if true,if the last select option is choose level x,then it will try to find anastor select's select value give the result text
        };

        var displayParents = function() {
            var labels = []; // initialize array
            $(this).siblings('select') // find all select
                           .find(':selected') // and their current options
                             .each(function() { labels.push($(this).text()); }); // and add option text to array
            $('
').text(this.value + ':' + labels.join(' > ')).appendTo('#demo6-result');  // 
and display the labels
            }

    $.getJSON('get-subtree.php', function(tree) { // initialize the tree by loading the file first
        $('#demo6').optionTree(tree, options).change(displayParents);
    });
});
</script>

Original comment by FREDERICK.Mao on 6 Nov 2010 at 2:10

Attachments:

GoogleCodeExporter commented 8 years ago
I also would like to see the features reported by FREDERICK.Mao merged into the 
trunk.

Have you looked at this issue kkotowicz?

Thank you?

Original comment by hugodur...@gmail.com on 19 Jan 2011 at 4:28

GoogleCodeExporter commented 8 years ago
I looked into the issue, but i don't want to require having ids on select 
fields, so we'll have to figure out how to implement this without relying on 
ids. Maybe $.data() additions?

Original comment by kkotowicz on 27 Jan 2011 at 1:45

GoogleCodeExporter commented 8 years ago
this is a serious bug which makes this control unusable.  this is a shame 
because it looks like you put a lot of thought into this.

FREDERICK.Mao's changes are a good solution and i monkey patched to get this 
control working.
you really ought to merge his changes.
then at least the control works while you are developing your alternate 
solution.

in any case, thanks for making this available!

Original comment by dimitri....@gmail.com on 25 Jul 2011 at 7:51

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r14.

Original comment by kkotowicz on 27 Jul 2011 at 4:32

GoogleCodeExporter commented 8 years ago
Applied the changes in r14. There are now two new options:
 - get_parent_value_if_empty (so it grabs value from parent, false by default) 
 - attr (to choose HTML attribute to use to track nested selects, 'name' by default)

Original comment by kkotowicz on 27 Jul 2011 at 4:34