Closed umer936 closed 3 years ago
Where exactly are you using $this->Form->addWidget()
? It should work fine in templates, but it could break the form helper loading "order" when used in a view class.
The first message in this thread was from the View class. I figured that was the case that it would break the Form helper. However, there are issues trying to use it in templates as well.
in templates/Pages/home.php
, putting
$this->Form->addWidget(
'autocomplete',
['Autocomplete', 'text', 'label']
);
results in
Cannot find template named 'autocomplete'.
Whereas putting
$autocomplete = new AutocompleteWidget(
$this->Form->getTemplater(),
$this->Form->getWidgetLocator()->get('text'),
$this->Form->getWidgetLocator()->get('label'),
);
$this->Form->addWidget('autocomplete', $autocomplete);
results in
Missing field name for FormHelper::getTemplater
I was thinking this was related to bootstrap-ui
overwriting the templates. I have not tried this in a fresh project without the plugin
The first error means that you have not (or incorrectly) added a template to the form helper, if you look in the linked book section, its done there using:
$this->Form->setTemplates([
'autocomplete' => '<input type="autocomplete" name="{{name}}" {{attrs}} />'
]);
The second error means that you possibly did something like $this->Form->autocomplete()
without an argument for the field name.
Oh wow. I did not understand the docs correctly.
This widget would render the “autocomplete” string template, such as:
$this->Form->setTemplates([
'autocomplete' => '<input type="autocomplete" name="{{name}}" {{attrs}} />'
]);
Made me think that simply doing the addWidget()
would make CakePHP run the setTemplates()
—not that I had to do it.
Works as intended.
Evidently not an issue with bootstrap-ui
.
Thank you for your help. Closing.
This is a (multiple allowed):
[x] bug
[ ] enhancement
[x] feature-discussion (RFC)
BootstrapUI Version:
dev-bs5
Bootstrap Framework Version:
5.1.1
jQuery:
N/A
Platform and Target:
CakePHP 4.2.10
What you did
Intend to create a file dropper/dropzone widget. Currently just trying to make Form add a new Widget using https://book.cakephp.org/4/en/views/helpers/form.html#adding-custom-widgets.
Expected Behavior
I am able to use
echo $this->Form->autocomplete('search', $options);
Actual Behavior
CakePHP Error
This is a feature discussion as the plugin should not remove the ability to add other custom Form fields.