Unified all modals into blade components - #19610
Merged
Merged
Conversation
Up to standards ✅🟢 Issues
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This moves the modals from
resources/views/modals/*into the blade components directory and updates them to use the form blade components.While I was testing this, I also realized that inline comments in the props break the IDE view, making it look like there's a parse error when there isn't one, so I moved those all to the top of the file in a blade comment. Shouldn't have been necessary, but at least it doesn't look borked now.
I also refactored the
form-rowblade component, because in some modals, we use a "vertical" form (BS parlance) and in others we use a horizontal form. For reference, all of our edit/create forms are vertical - it's what Bootstrap defaults to, and is generally better for larger screens. That's the model where you have a label and then to the right, the input field.Horizontal forms are only used in a few modals (though that might change - they do look better in modals) where the label is stacked on TOP of the input field, like the replenish modal:
So the
form-rowblade will work as expected as-is, but now pulls in the field logic (date picker, text, textarea, etc) into its own blade component, just to keep the form-row blade a bit clearer. Now it only handles the layout, and the newfieldcomponent handles which field type needs to be slotted in.I once again ran into the weird ID problem where clicking on a "new" modal button would trash the company select2 on parent page. That's fixed now by adding the modal ID so that select2 has its own modal ID that doesn't step on the other select lists on the page.
(Sorry for all the inline-comment-moving noise in this one - seemed like a good opportunity to fix it, but it probably should have been in another PR.)
There are THREE categories of modal (and two styles):
AJAX modal (loaded into
#createModalvia "New" buttons)Used when a
-selectpicker's "New" button opens a modal to create a resource on the fly and inject the saved value into the corresponding select2 that exists on the parent page.This is rendered by
ModalController::showwhen the trigger points atroute('modal.show', 'blahblah'). The API endpoint's JSON response must includepayload.idandpayload.nameso the JS can push a new option into the trigger select2.Nested
-selectwidgets auto-hide their own "New" buttons (via@aware) since#createModalis single-slot (and we wouldn't want to open a modal on top of another modal.) Passid="modal_<name>_select"on any-selectto avoid a duplicate id if the parent page also renders that picker.Standalone modal (inline on the page)
Used for uploads and inline forms that submit natively. Existing examples:
adjust-quantity,request-item,maintenance-complete,add-note,upload-file,confirm-action.Global confirm modal (delete / restore)
This has existed for a long time, but it bears repeating here: don't roll your own confirm dialog.
layouts/default.blade.phprenders#dataConfirmModal(delete) and#restoreConfirmModal(restore) once for the whole app. Attributes on.delete-assetand.restore-assetin snipeit.js populate the modal's form action from the trigger'sdata-href/hrefand open it.You can create these just by giving it the right class + data attributes. No blade needed.
Same for restore, use
restore-assetclass.Note: We would normally not use an
<a>for changing data - that should be a POST request, not a GET - but because there is another layer, the confirmation modal, it's okay. Maybe.Layout
Horizontal (BS3 label-left) is the default. Pass
stackedon<x-modals>for a vertical form. Rows inside inherit it automatically.Props:
idnull.modalwrapper. Omit for AJAX modals (they land inside the shared#createModal). Required for standalone modals so their trigger'sdata-target="#..."finds them.titlenull.modal-titlein the header. Skip if you supply<x-slot:header>.actionnullsubmitToSelect2false.modal-body, save button is#modal-saveoutside the form, and the delegated jQuery handler POSTs the form and pushes the created row into the trigger<select>.stackedfalseform-horizontal(BS3 label-left grid, matches every regular edit/create form).stacked= vertical form (labels above inputs). Must be paired with<x-form.row stacked>on each row inside.submit_labeltrans('general.save')submit_class'btn-primary'btn-dangerfor destructive confirms,btn-successfor state advancement,btn-themefor uploads.form_classnull<form>element on top of the layout default. Rarely needed.form_attrs''<form>. Use forenctype="multipart/form-data", extraids that JS keys off,accept-charset, etc.labelledbyaria-labelledbytarget on the outer wrapper. Auto-derived as{$id}Label. Override only if the accessible name lives elsewhere in your custom header slot.Slots:
header$title). Use for icons or dynamic titles that snipeit.js swaps at open time.footer