ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

UI-Bootstrap typeahead doesn't work in editable grid

Open mattsharpe opened this issue 11 years ago • 41 comments

Hi guys, I'm using the ui-bootstrap inside my grid and hitting some issues, I've read through #3115 but the plunker in the solution doesn't seem right. http://plnkr.co/edit/ai91kJMiApXktc4vM4mt?p=preview Try typing 'New' in the first row then hitting enter to select 'New Hampshire', nothing happens.

I'm seeing the same behaviour in my app, no keyboard select or mouse select will work to choose a drop down item. Any ideas?

mattsharpe avatar May 10 '15 18:05 mattsharpe

Hi, call to 'data-typeahead-on-select="typeaheadSelected(row.entity, $item)" ' also doesn't work. I think it is related to the autocomplete.

trytocatchme avatar May 15 '15 09:05 trytocatchme

I'm not sure that's currently supported, I think someone would have to dig through it. No doubt we're trapping the enter key and using it for something else, so you might need to dig through the code and work out where. At a guess I'd say the edit feature is trapping it.

PaulL1 avatar May 16 '15 04:05 PaulL1

Using this cell template with appScope still typeahead very consufed

<form name="inputForm"> <div class="typeaheadcontainer"><input type="text" ' +
            'class="typeaheadcontrol" ' +
            'ui-grid-editor ' +
            'data-ng-model="grid.appScope.mymodel" ' +
            'data-typeahead="name as state.name for state in grid.appScope.states | filter:$viewValue | limitTo:8" ' +
            'data-ng-required="true" ' +
            'data-typeahead-editable ="false"' +
            //'data-typeahead-on-select="grid.appScope.typeaheadSelected($item, $model, $label)" ' +
            '/></div></form>

I have tracked it down inside typeahead ui-bootstrap-tpls.js

} else if (evt.which === 13 || evt.which === 9) {
          scope.$apply(function () {
            scope.select(scope.activeIdx);
          });

        }

Something is wrong with the scope and type ahead fails to call select and if I modify this to

ui-bootstrap-tpls.js

} else if (evt.which === 13 || evt.which === 9) {
          scope.select(scope.activeIdx);
         scope.$apply(function () {
            scope.select(scope.activeIdx);
          });

        }

then inside select it fails to workout selected text

model = parserResult.modelMapper(originalScope, locals);

So it seems grid.appScope is the issue.

Would be awesome to get typeahead working with ui-grid as I am currently looking for other options like jquery autocomplete and not looking forward for that.

unkn0wn-kgb avatar Jun 02 '15 08:06 unkn0wn-kgb

+1 I'm stuck on this too, and can't find a work-around; frankly it is beyond my DOM expertise.

willw-git avatar Jun 03 '15 10:06 willw-git

Yes that would be awesome to get typeahead working with ui-grid however I've started on jquery ui autocomplete integration and creating a custom directive for binding so far its going ok, much easier than getting typeahead to work properly without modifying the core. I hope one day this would get done with typeahead would even pay for this feature.

unkn0wn-kgb avatar Jun 03 '15 10:06 unkn0wn-kgb

+1

hydra1983 avatar Jun 04 '15 11:06 hydra1983

scope.$apply(function () {
    scope.select(scope.activeIdx);
});

The inside "select" is not executed in my situation.

hydra1983 avatar Jun 05 '15 04:06 hydra1983

scope.select(scope.activeIdx);
scope.$apply();

Putting the "select" outside $apply can have "enter" key working, but the mouse click takes no effect.

image

image

hydra1983 avatar Jun 05 '15 05:06 hydra1983

Yeah same results here, that handsontable that you have mentioned does look promising, let me know how that goes

unkn0wn-kgb avatar Jun 05 '15 07:06 unkn0wn-kgb

The $apply funciton is "noop" when working with ui-grid together. That's the reason the inner line can not be executed I think.

screen shot 2015-06-07 at 17 18 15

It should be something like this,

screen shot 2015-06-07 at 17 23 50

hydra1983 avatar Jun 07 '15 09:06 hydra1983

The "$apply" is "noop" only when lines below executed:

scope.$apply(function () {
    scope.select(scope.activeIdx);
});

Quite strange

hydra1983 avatar Jun 07 '15 10:06 hydra1983

On "enter" "keydown", image

stopEdit is called and which will destroy the originalScope

image

So the $apply of scope in the lines below will be noop after originalScope is destroyed.

image

hydra1983 avatar Jun 07 '15 11:06 hydra1983

So is it possible to write hack to overwrite endEdit?

unkn0wn-kgb avatar Jun 08 '15 00:06 unkn0wn-kgb

The event should be bubbled from the inner typeahead to the outer ui grid I think. But the actual direction is contrary. I'm looking for the cause. The solution should be, the keydown handler of typeahead is executed before the keydown handler of ui grid.

hydra1983 avatar Jun 09 '15 04:06 hydra1983

image

image

Seems the event bind to the same element, and ui grid bind the event earlier than typeahead. Follow the rule First come and first out(See here), the event handler bind in ui grid will be executed firstly.

hydra1983 avatar Jun 09 '15 05:06 hydra1983

The solution 2 here can resolve this problem. But need tests to make sure other functions are not affected.

image

hydra1983 avatar Jun 09 '15 05:06 hydra1983

This is not the best solution I think. A better way should be capturing keydown event on typeahead popup and process the logic to change the model then propagate the event to ui-grid.

hydra1983 avatar Jun 09 '15 05:06 hydra1983

not sure if this will help, but I had a similar problem with angular ui-grid edit with typeahead autocomplete.

i could not select values from the list with my mouse until I used

typeahead-select-on-blur="true"

brick80 avatar Oct 20 '15 12:10 brick80

I'm not sure what is the issue here - I was able to get it to work here.

wesleycho avatar Oct 20 '15 21:10 wesleycho

@wesleycho Issue is that model data does not gets bind. Try to bind object then see if that objects gets changed it won't. See my comments above. (grid.appScope.typeaheadSelected($item, $model, $label))

Not only that typeahead has to visually work but also it should be able to bind models appropriately. I hope this helps

unkn0wn-kgb avatar Oct 20 '15 21:10 unkn0wn-kgb