-
-
Notifications
You must be signed in to change notification settings - Fork 236
Add fieldset formwidget #1435
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
Open
mjauvin
wants to merge
17
commits into
develop
Choose a base branch
from
fieldset-formwidget
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+199
−0
Open
Add fieldset formwidget #1435
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
18113c3
add fieldset formwidget
mjauvin b53bc99
remove extra semicolon
mjauvin bebc32e
use label instead of placeholder for fieldset legend
mjauvin 9165f93
add missing docblock
mjauvin a96d8b8
Merge branch 'develop' into fieldset-formwidget
LukeTowers 2422ce1
Apply suggestion from @LukeTowers
LukeTowers b7cf609
only use outside fields as this is only for defining the grouped fields
mjauvin b7442e1
escape the label.
mjauvin b78bc05
fix codestyle
mjauvin 02a0fdd
we need fields, not just fields configs
mjauvin 9d552fc
Merge branch 'develop' into fieldset-formwidget
mjauvin 11faa45
add application exception for unsupported fields
mjauvin 9c885c0
add missing space after coma
mjauvin 116c95c
add support for formwidgets as fieldset internal fields
mjauvin f13f024
improve style
mjauvin f133d71
use switch statement
mjauvin 5458cae
does not save anything itself
mjauvin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <?php | ||
| namespace Backend\FormWidgets; | ||
|
|
||
| use Backend\Classes\FormWidgetBase; | ||
| use Backend\Widgets\Form; | ||
|
|
||
| /** | ||
| * FieldSet | ||
| * Renders a fieldset from multiple form fields. | ||
| * | ||
| * @package winter\wn-backend-module | ||
| * @author Marc Jauvin <marc.jauvin@gmail.com> | ||
| */ | ||
| class FieldSet extends FormWidgetBase | ||
| { | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| protected $defaultAlias = 'fieldset'; | ||
|
|
||
| /** | ||
| * @var array Form configuration | ||
| */ | ||
| public $form; | ||
|
|
||
LukeTowers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public $showLabels = false; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * @var Form form widget reference | ||
| */ | ||
| protected $formWidget; | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| public function init() | ||
| { | ||
| $this->fillFromConfig([ | ||
| 'form', | ||
| ]); | ||
|
|
||
| if ($this->formField->disabled) { | ||
| $this->previewMode = true; | ||
| } | ||
|
|
||
| $config = $this->makeConfig($this->form); | ||
| $config->model = $this->model; | ||
| $config->data = $this->getLoadValue(); | ||
| $config->alias = $this->alias . $this->defaultAlias; | ||
| // set arrayName from parent form to save fields to the model | ||
| $config->arrayName = $this->getParentForm()->arrayName; | ||
| $config->isNested = true; | ||
|
|
||
| $this->formWidget = $widget = $this->makeWidget(Form::class, $config); | ||
| $widget->previewMode = $this->previewMode; | ||
| $widget->bindToController(); | ||
| } | ||
|
|
||
| protected function loadAssets() | ||
| { | ||
| $this->addCss('css/fieldset.css', 'core'); | ||
| } | ||
|
|
||
| public function getFormFields() | ||
| { | ||
| return $this->formWidget->getFields(); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function render() | ||
| { | ||
| $this->prepareVars(); | ||
| return $this->makePartial('fieldset'); | ||
| } | ||
|
|
||
| public function prepareVars() | ||
| { | ||
| $this->formWidget->previewMode = $this->previewMode; | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
modules/backend/formwidgets/fieldset/assets/less/fieldset.less
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| @import "../../../../assets/less/core/boot.less"; | ||
|
|
||
| @panel-bg: #f5f5f5; | ||
| @panel-bg-dark: #000; | ||
|
|
||
| .fieldset { | ||
| position: relative; | ||
| min-height: 30px; | ||
|
|
||
| border: 1px solid @input-border; | ||
| border-radius: 0.5rem; | ||
| box-shadow: @input-box-shadow; | ||
|
|
||
| margin-top: 5px; | ||
| padding: 1em 1.25em 0 1.25em; | ||
|
|
||
| background: @panel-bg; | ||
| @media (prefers-color-scheme: dark) { | ||
| background: @panel-bg-dark; | ||
| } | ||
|
|
||
| & > legend { | ||
| border: none; | ||
| margin: 0; | ||
| padding-inline: 1rem; | ||
| width: fit-content; | ||
| font-size: 18px; | ||
| color: inherit; | ||
| } | ||
| .control-tabs.primary-tabs { | ||
| .nav-tabs { | ||
| margin: 0; | ||
| > li.active > a:before { | ||
| background-color: @panel-bg; | ||
| border-color: @panel-bg; | ||
| @media (prefers-color-scheme: dark) { | ||
| background-color: @panel-bg-dark; | ||
| border-color: @panel-bg-dark; | ||
| } | ||
| } | ||
|
|
||
| > li > a > span.title { | ||
| &:before, &:after { | ||
| background-color: @panel-bg; | ||
| @media (prefers-color-scheme: dark) { | ||
| background-color: @panel-bg-dark; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
mjauvin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php $label = object_get($this->config, 'label'); ?> | ||
|
|
||
| <fieldset class="fieldset"> | ||
| <?php if ($label): ?> | ||
| <legend><?= trans($label) ?></legend> | ||
mjauvin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <?php endif ?> | ||
|
|
||
| <?= $this->formWidget->render() ?> | ||
| </fieldset> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.