Samples of autocomplete feature (in development).
All use twitter typehaead and
Bloodhound (Suggestion Engine).
The last one also uses TagsInput.
class DemoController extends Controller
....
public function anyAdvancedform()
{
$form = \DataForm::source(Article::find(1));
$form->add('title','Title', 'text')->rule('required|min:5');
//simple autocomplete on options (built as local json array)
$form->add('author_id','Author','autocomplete')->options(Author::pluck('firstname', 'id')->all());
//autocomplete with relation.field to manage a belongsToMany
$form->add('author.fullname','Author','autocomplete')->search(array("firstname", "lastname"))->limit(5);
//autocomplete with relation.field, returned key, custom remote ajax call (see at bottom)
$form->add('author.firstname','Author','autocomplete')->remote(null, "id", "/rapyd-demo/authorlist");
//tags with relation.field to manage a belongsToMany, it support also remote()
$form->add('categories.name','Categories','tags');
$form->submit('Save');
$form->saved(function () use ($form) {
$form->message("ok record saved");
$form->link("/rapyd-demo/advancedform","back to the form");
});
return view('rapyd::demo.advancedform', compact('form'));
}
public function getAuthorlist()
{
//needed only if you want a custom remote ajax call for a custom search
return Author::where("firstname","like", \Request::get("q")."%")
->orWhere("lastname","like", \Request::get("q")."%")->take(10)->get();
}