preaction / Yancy

The Best Web Framework Deserves the Best Content Management System
http://preaction.me/yancy/
Other
54 stars 21 forks source link

Adding skip_fields option at Yancy::Plugin::Form::Bootstrap4 form_for #93

Closed pavelsr closed 4 years ago

pavelsr commented 4 years ago

E.g. I have schema

CREATE TABLE users (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `username` VARCHAR(255) NOT NULL,
  `email` VARCHAR(255) NOT NULL,
  `phone` VARCHAR(255) NOT NULL,
  `password` VARCHAR(40) NOT NULL,
  `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `is_admin` BOOL,
  UNIQUE KEY (`username`,`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

If I call form_for there is no way to skip fields like id, created, is_admin which are typically not required for user input.

pavelsr commented 4 years ago

Merge request: #94

preaction commented 4 years ago

This was solved in a couple ways:

Thanks for reporting this and providing a patch!

pavelsr commented 4 years ago

Hey Doug! Seems like we should add skip_fields arg in addition to properties I found at least one use case where it could be extremelly usefull - skipping user_id field in item add/edit form in multiTenant apps.

pavelsr commented 4 years ago

Code example:

# controller:
$user_route->get('/bank_details/edit/:id')->to( 'yancy-multi_tenant#get', schema => 'bank_details', template => 'bank_detail_edit' ); 
# bank_detail_edit.html.ep
%= $c->yancy->form->form_for( 'bank_details', skip_fields => [ 'id', 'user_id' ] ); 

For now I have to use long and not elegant construction:

properties => [ grep { $_ !~ /id/ } keys %{ $c->yancy->backend->schema->{bank_details}{properties} } ]