New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add help_block doesn´t work #238
Comments
Hi, i'll check it out, thanks for reporting. What version are you using? |
Laravel 5.2 and laravel-form-builder 1.7.10 |
It works fine for me. Did you use any older versions, and than update it? |
No, complete new development with out custom views. i just use the normal types that are defined out of the box. The only thing is that it is an form builder for normal employees without knowledge about php or html. I first used. I have one Formobject that will be dynamicly filled @ buildForm but this can't be a problem, or? i just run add with text, select, checkbox, or so in one foreach. I`ll add the complette buildForm hear. |
*/
public function buildForm()
{
foreach ($this->_form->inputs as $input){
/**
* @var $input Input
*/
$inputType = InputTypRepository::getRepository()->find($input->type);
$input_name = ($inputType->inputName === false) ? (($input->object_field == '') ? str_slug($input->label,'') : $input->object_field): $inputType->inputName;
$readOnly = ($input->isReadOnly()) ? ['disabled'] : [];
$options = [
'label' => _($input->label),
'attr' => (empty($this->formOptions['attr']) ? $readOnly: array_merge($readOnly,$this->formOptions['attr'])),
];
if(!$input->isReadOnly()){
self::addRule($input_name,($input->isRequired() ? 'required|': '').$inputType->validation_rule);
}
if($inputType->formBuilderTyp == 'select'){
if($inputType->getOptions() !== null){
$options = array_merge($options,['choices' => $inputType->getOptions()]);
} else {
$options = array_merge($options,['choices' => explode('|',$input->options)]);
}
if($this->model instanceof Model){
$options = array_merge($options,['selected' => eval('return $this->model->'.$input->object_field.';')]);
}
$options = array_merge($options,['empty_value' => '--- Bitte wählen ---']);
}
if($input->helpBlock != null){
$options['help_block'] = ['text' => $input->helpBlock,'tag' => 'p','attr' => ['class' => 'help-block']];
}
$this->add($input_name,$inputType->formBuilderTyp,$options);
}
$this->addDefaultActions();
} |
It shouldn't be a problem, but try creating a field without all this code. So just comment it out and try something like this: $this->add('name', 'text', [
'help_block' => [
'text' => 'This is help block message',
'tag' => 'p',
'attr' => ['class' => 'help-block']
]
); And if that works, than it's problem in your logic somewhere, if not, it's in the package. |
public function buildForm()
{
/* foreach ($this->_form->inputs as $input){
/**
* @var $input Input
*/
/* $inputType = InputTypRepository::getRepository()->find($input->type);
$input_name = ($inputType->inputName === false) ? (($input->object_field == '') ? str_slug($input->label,'') : $input->object_field): $inputType->inputName;
$readOnly = ($input->isReadOnly()) ? ['disabled'] : [];
$options = [
'label' => _($input->label),
'attr' => (empty($this->formOptions['attr']) ? $readOnly: array_merge($readOnly,$this->formOptions['attr'])),
];
if(!$input->isReadOnly()){
self::addRule($input_name,($input->isRequired() ? 'required|': '').$inputType->validation_rule);
}
if($inputType->formBuilderTyp == 'select'){
if($inputType->getOptions() !== null){
$options = array_merge($options,['choices' => $inputType->getOptions()]);
} else {
$options = array_merge($options,['choices' => explode('|',$input->options)]);
}
if($this->model instanceof Model){
$options = array_merge($options,['selected' => eval('return $this->model->'.$input->object_field.';')]);
}
$options = array_merge($options,['empty_value' => '--- Bitte wählen ---']);
}
if($input->helpBlock != null){
$options['help_block'] = ['text' => $input->helpBlock,'tag' => 'p','attr' => ['class' => 'help-block']];
}
$this->add($input_name,$inputType->formBuilderTyp,$options);
} */
$this->add('teeest', 'text', [
'help_block' => [
'text' => 'This is help block message',
'tag' => 'p',
'attr' => ['class' => 'help-block']
]
]
);
$this->addDefaultActions();
} |
really strange. What's |
Adds only the button: /**
*
*/
public function addDefaultActions()
{
$this->add('submit', 'submit',
[
'label' => 'Speichern',
'attr' => [
'class' => 'btn btn-success'
],
])
->add('back', 'button',
[
'label' => 'Zurück',
'attr' => [
'class' => 'btn btn-default',
'onclick' => 'window.history.back()'
],
]); |
I'm not able to reproduce. What did you put in the view? |
i just make form($theFormBuilderInstance). /**
* @param string $key
* @return string
* @throws \ErrorException
*/
public function render($key, array $options = [], array $data = [])
{
$form = Form::where('key', '=', $key)->first();
if ($form instanceof Form) {
if($form->action == 'database'){
$options = array_merge($options, ['model' => eval('return ' . $form->action_url . ';')]);
}
if ($form->action == 'url') {
$options = array_merge($options,['url' => $form->action_url]);
}
$form = $this->_container
->make(DynamicForm::class, [$form])
->setFormHelper($this->_formHelper)
->setFormBuilder($this)
->setFormOptions($options)
->addData($data)
->setRequest(request());
$form->buildForm();
return form($form);
} else {
throw new \ErrorException('Can´t find Form with Key: ' . $key);
}
} Form:: is as Model that represents the form in the Database in the Form i only make {!! FormRender::render('key_from_form') !!} |
can you just create a form with FormBuilder class in a controller, pass it to view, and in view use |
I used the complete Sample: Form: namespace App\Forms;
use Kris\LaravelFormBuilder\Form;
class SongForm extends Form
{
public function buildForm()
{
$this
->add('name', 'text')
->add('lyrics', 'textarea')
->add('publish', 'checkbox',['help_block' => ['text' => 'helpBlock Works!']]);
}
} Controller: public function test(FormBuilder $formBuilder)
{
$form = $formBuilder->create('App\Forms\SongForm', [
'method' => 'POST',
'url' => '/test'
]);
return view('welcome', compact('form'));
}
} View: @extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">Welcome</div>
<div class="panel-body">
{!! form($form) !!}
</div>
</div>
</div>
</div>
</div>
@endsection |
And when i try to modify the publish input: use Kris\LaravelFormBuilder\Form;
class SongForm extends Form
{
public function buildForm()
{
$this
->add('name', 'text')
->add('lyrics', 'textarea')
->add('publish', 'checkbox');
$this->modify('publish','checkbox',['help_block' => ['text' => 'helpBlock Works!']],false);
}
} |
@kristijanhusak i think i founded it... first i had https://github.com/Distilleries/FormBuilder installed, with his views. I removed this without thinking about the published views and installed the base builder (your package). This was the error with all ;) Thank you! |
Great. Closing this. |
Hello,
i have the problem that i can't add the help_block (dynamic).
The Code:
And the result is an Select Input with all other options that i define, but without the helpblock.
So it is the same as in the documentation... Can you help? Or is that a Bug?
Laravel 5.2 and laravel-form-builder 1.7.10
Thank You! @kristijanhusak
The text was updated successfully, but these errors were encountered: