DataForm (advanced stuffs)

Samples of autocomplete feature (in development).
All use twitter typehaead and Bloodhound (Suggestion Engine).
The last one also uses TagsInput.

  • The most simple is the first one, it simply builds a local json array using options()
  • The second one is the smarter, using relation.fieldname as fieldname and search(array of search fields)
    rapyd will manage an ajax request to instace a related entity, search on search fields, and store the foreign key on select
  • The third is the more complete, it is like the second one with the added ability to customize the search query
  • The last is a sample of the "tags" field to manage a belongsToMany and it also supports search() and remote()

The only options available in this demo are "Jane" and "Jhon", it is just a test form to show it works properly.
In the same spirit, the only categories available are "Category 1" up to "Category 5".




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"));

        
//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", \Input::get("q")."%")
            ->
orWhere("lastname","like", \Input::get("q")."%")->take(10)->get();

    }