简体   繁体   中英

Populate form with previous data

I'm looking to add a feature to my application which currently, you enter your first name and last name and a few other details.

What I want to add is the ability to start typing the first name in the form and instantly output those with a similar name and if the name is there then use those details rather than entering the name again.

Once you've selected the name of a previous entry you can carry on adding the data to the form for the fields not populated.

I'm currently working with laravel any insight to tackling this one would be greatly appreciated.

Thanks

I have done this before but not in Laravel. The concepts should be mostly the same. The issue you will run into is how you want to qualify similar. If similar means you can use a "like" query against values the start with what has been typed against a database table, it's super easy. The simple way is going to perform a query like this:

$users = DB::table('users')
            ->where('name', 'like', 'rob%')
            ->get();

Because the wildcard is at the end, you can still use a standard database index to prevent your lookups from killing your database.

If you want something more advanced, you'll have to figure out indexing schemes and possibly use a full-text index server like Lucene . We ended up with the latter.

In either case, you will need an API endpoint that works with a front-end widget. I believe we used the JQuery plugin Select2 . It has an example to make it work for a remote data set with Ajax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM