Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Conversation

@J87NL
Copy link
Contributor

@J87NL J87NL commented Mar 25, 2023

As requested in the Splade Discord so we are able to do:

->label(__('Title <span class="text-red-500">*</span>'))

As requested in the Splade Discord so we are able to do:

```php
->label(__('Title <span class="text-red-500">*</span>'))
```
@J87NL
Copy link
Contributor Author

J87NL commented Mar 26, 2023

Could be a nice idea to automatically add a red star to the label when a field is marked as required, I'm working on this.

@AliasSuperman
Copy link

I achieved it like this: in form.label.blade.php

<span class="mb-1 block font-sans text-gray-700"> {{ $label }}@if ($attributes->has('required')) <span class="text-red-500">*</span> @endif </span>

@J87NL
Copy link
Contributor Author

J87NL commented Mar 27, 2023

@AliasSuperman just added this approach, had to add required to the attributes for this.
I'm not entirely convinced this HTML5-validation is the desired way to go because you now get the 'Please fill in this field' when trying to submit instead of the formvalidation message below the field after submitting. It feels a bit like not using the power/charms of Splade, what do you think @pascalbaljet?

@pascalbaljet
Copy link
Contributor

I'm not a fan of the default HTML5 validation capabilities. I would suggest adding htmlLabel and htmlHelp methods, and allow passing a HtmlString to the label and help methods:

Input::make('hiddenInput2')
    ->htmlLabel('Title <span class="text-red-500">*</span>');

// which will be a shortcut to:

Input::make('hiddenInput2')
    ->label(new HtmlString('Title <span class="text-red-500">*</span>'));

#378

@J87NL J87NL changed the title Allow HTML in form labels Automatically add a red star to the label when a field is marked as required Apr 2, 2023
@J87NL J87NL marked this pull request as draft April 2, 2023 11:26
@MdAnowarHosen
Copy link

Good idea!

@J87NL J87NL marked this pull request as ready for review May 7, 2023 10:25
@pascalbaljet
Copy link
Contributor

@J87NL Can this PR be closed now that we have htmlLabel()?

@J87NL
Copy link
Contributor Author

J87NL commented Jun 14, 2023

Preferably not, this PR adds the red asterisks automatically to all FormBuilder Splade-fields that have a required rule, so without the need of adding extra htmlLabels to all fields where you want one.

I've added a config variable to enable/disable the asterisks.

@pascalbaljet
Copy link
Contributor

Must admit it's quite nice! One more question: what the reason behind using data-required in the Form Builder instead of the required attribute?

@J87NL
Copy link
Contributor Author

J87NL commented Jun 14, 2023

Just 'required' would make it HTML5-validation which would prevent the form from being able to submit, and therefore you won't see the formrequest validation.

@pascalbaljet pascalbaljet merged commit 3c61681 into protonemedia:main Jun 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants