Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete Select Component #6355

Open
sanhofman opened this issue Nov 5, 2021 · 5 comments
Open

Autocomplete Select Component #6355

sanhofman opened this issue Nov 5, 2021 · 5 comments
Labels
Feature New functionality not yet included in Sulu UX Affecting the end user

Comments

@sanhofman
Copy link
Contributor

sanhofman commented Nov 5, 2021

Problem description

An autocomplete select component which enables autocomplete search on a given list of results.

Proposed solution

Possible solution:

import React from "react";
import { observer } from "mobx-react";
import { action, observable } from "mobx";
import SingleAutoComplete from "sulu-admin-bundle/components/SingleAutoComplete";

// 2 params are required:
// list: array with possible results, each item must have an ID
// list_key: defines which key you want to display and search on

@observer
class InputAutoComplete extends React.Component {
  @observable suggestions = [];
  @observable selectedLanguage = {};

  @action handleChange = (value) => {
    this.selectedLanguage = value;
    this.suggestions = [];
    this.props.onChange(value?.id ?? undefined);
  };

  @action handleSearch = (value) => {
    if (value) {
      this.suggestions = this.props.schemaOptions.list.value.filter((item) =>
        item[this.props.schemaOptions.list_key.value]
          .toLowerCase()
          .includes(value.toLowerCase())
      );
    }
  };

  render() {
    return (
      <SingleAutoComplete
        displayProperty={this.props.schemaOptions.list_key.value}
        onChange={this.handleChange}
        onSearch={this.handleSearch}
        searchProperties={[this.props.schemaOptions.list_key.value]}
        suggestions={this.suggestions}
        value={this.value}
      />
    );
  }
}
export default InputAutoComplete;
        <property name="languageCode" type="input_autocomplete" mandatory="true" colspan="12">
            <meta>
                <title>Language</title>
            </meta>
            <params>
                <param name="list" type="expression" value="service('App\\Service\\Admin\\AdminLanguageService').getLanguages()"/>
                <param name="list_key" value="title"/>
            </params>
        </property>

Contribution

This could be interesting to include as Sulu component?

@sanhofman sanhofman added the Feature New functionality not yet included in Sulu label Nov 5, 2021
@alexander-schranz alexander-schranz added the UX Affecting the end user label Nov 19, 2021
@alexander-schranz
Copy link
Member

@sanhofman Thank you for sharing your component here with us. This sounds like a great suggestion. I think it would be great if maybe we could improve our selects maybe always with some kind of filter / autocomplete handling. But think we need to check this first with our UI/UX consultants.

@nicolas-joubert
Copy link

Hello @sanhofman,
i've got the same need, so have you finally implemented it ?
Regards,

@sanhofman
Copy link
Contributor Author

Hi @nicolas-joubert,

Yes we have used a custom component like mentioned above.

But would still be a great addition to provide this within Sulu!

@nicolas-joubert
Copy link

hi @sanhofman,
i've implemented your react component with a fake contentType. Rendering works but not save into model. Could you had Symfony part of the custom component, thanks ?

@nicolas-joubert
Copy link

After using 'id' for keys and change render value to {this.props.schemaOptions.list.value.find(({id}) => id === this.props.value)} it work on sulu 2.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New functionality not yet included in Sulu UX Affecting the end user
Projects
None yet
Development

No branches or pull requests

3 participants