Comments (14)
Ah, nullable doesn't exist in 5.2 we should probably add a check indeed.
from laravel-form-bridge.
So I can add the required rule when the required
option is set, but the other way around doesn't seem to work; b4a4348
from laravel-form-bridge.
So front-end validation is roughly working: 64ff0cb
And setting default required state with the config: f1ccbc1
Could perhaps add some rules based on the type (eg Emailtype -> add email rules), but not really sure if that's possible.
from laravel-form-bridge.
https://laravel.com/docs/5.4/upgrade#upgrade-5.4.0
Validation: Method Names
The addError method has been renamed to addFailure. In addition, the doReplacements method has been renamed to makeReplacements. Typically, these changes will only be relevant if you are extending the Validator class.
from laravel-form-bridge.
When no rules defined:
BadMethodCallException in Validator.php line 3295:
Method [validateNullable] does not exist.
This is my composer dependencies:
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"barryvdh/laravel-form-bridge": "^0.3.2"
},
Temporary solution: comment lines 49-51 in ValidationTypeExtension
if (!in_array('required', $rules) && !in_array('nullable', $rules)){
$rules[] = 'nullable';
}
from laravel-form-bridge.
Should be fixed with latest v0.3.3
from laravel-form-bridge.
Since #30 got closed, I'd like to mention that I got an issue with validation using the CollectionType in my parent form. Figured out that constraints (validation by Symfony Form itself) is working well. It seems that rules (implemented by @barryvdh ) don't work on child forms...
Any hint @barryvdh? I have no clue XD
Regards, Bob
from laravel-form-bridge.
Do you have a test case?
from laravel-form-bridge.
I'll post some code tomorow. Or do you prefer unit tests?
from laravel-form-bridge.
Nee a simple thing I can put in my own Laravel app is fine
from laravel-form-bridge.
What about this? Simplified it but should work...
Parent
<?php
namespace App\Core\Http\Forms\Types;
use Illuminate\Validation\Rule;
use Laravel\Nova\Fields\Number;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
class ParentFormType extends AbstractType
{
public function __construct()
{
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$auth = auth();
$builder
->add('sizeTo', NumberType::class, [
'required' => true,
'rules' => [
'min:00',
'max:99'
]
])
->add('weight', NumberType::class, [
'required' => false,
'rules' => [
'numeric'
]
])
->add('weightUnit', TextType::class, [
'required' => false,
'rules' => [
Rule::in(['kg', 'ha'])
]
])
->add('childs', CollectionType::class, [
'label' => false,
'entry_type' => ChildType::class,
'allow_add' => true,
])
->add('submit', SubmitType::class);
}
}
Child
<?php
namespace App\Core\Http\Forms\Types;
use Illuminate\Validation\Rule;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ChildType extends AbstractType
{
public function __construct()
{
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$auth = auth();
$builder
->add('class', TextType::class, [
'required' => true,
])
->add('size', NumberType::class, [
'required' => true,
'rules' => [
'min:00',
'max:99'
]
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => ParentData::class,
]);
}
}
from laravel-form-bridge.
I recreated this and added a level deeper. I made some changes (see 746fae0) and now I get this rule set:
It should add the validation for the children when at least 1 of the children is in the form input.
You can test this with 0.5@dev
, can you check it out?
from laravel-form-bridge.
Great work Barry! I'll check it out Monday morning! Have a nice weekend.
from laravel-form-bridge.
Hi there! It's me again :) last week I got some new validation issues with collections combined with Laravel's rules. I'll dig into this and I'll try to create a reproduction.
from laravel-form-bridge.
Related Issues (17)
- suggestion for syntax HOT 4
- Error with view rendering HOT 7
- Phpstorm syntax highlighting for blade directive HOT 6
- Twig caching HOT 5
- Directives not work HOT 2
- The option "constraints" does not exist.
- Nested form types validation HOT 1
- Error after some updates HOT 18
- Form types extensions doesn't work HOT 2
- Use blade instead of twig HOT 1
- PHP 7.4 - not using Template HOT 1
- Whole form is rendered, even though just one row is called HOT 2
- Change form template on the fly
- Array Validations not showing in twig
- Cache does not refresh after template changes?
- Laravel 9 support? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-form-bridge.