Skip to content

Opening tag "input" not terminated when it includes conditional logic. #123

@mattmarkwick

Description

@mattmarkwick

Hi, great project, thank you.

I have an issue running prettier using the prettier-plugin-blade.

We're using the Spatie laravel-permission package. Given an input with their custom @unlessrole directive inside it, I'm getting an error Opening tag "input" not terminated.

<div class="col-span-6">
    <label for="id" class="block text-sm font-medium text-gray-700">
        ID
    </label>
    <input wire:model.defer="id"
           type="text"
           class="w-full shadow-sm text-sm border-gray-300 rounded-md"
           @unlessrole('admin') disabled @endunlessrole
    >
    @error('id')
         <span class="text-sm text-red-400">
              {{ $message }}
         </span>
    @enderror
</div>

When I remove the line @unlessrole('admin') disabled @endunlessrole it runs fine with no error.

I have tried adding the unlessrole directive to the customIfs option in .blade.format.json but this has not helped:

{
    "useLaravelPint": true,
    "attributeJsOptions": {
        "semi": true,
        "tabWidth": 4,
        "trailingComma": "all"
    },
    "customIfs": ["unlessrole"]
} 

UPDATE/MORE INFO:

Since posting the above I have tried a couple of ways to get around the issue by changing my code, that you may find useful to know.

Both of the following examples resulted in the same error that the input tag was not terminated:

    <input wire:model.defer="id"
           type="text"
           class="w-full shadow-sm text-sm border-gray-300 rounded-md"
           {{ auth()->user()->hasRole('admin') ? '' : 'disabled' }}
    >
    <input wire:model.defer="id"
           type="text"
           class="w-full shadow-sm text-sm border-gray-300 rounded-md"
           @if(!auth()->user()->hasRole('admin')) disabled @endif
    >

I was able to get the formatter to run without error by moving the conditional outside of the input tag:

@unlessrole('admin')
    <input wire:model.defer="id"
           type="text"
           class="w-full shadow-sm text-sm border-gray-300 rounded-md"
           disabled
    >
@else
    <input wire:model.defer="id"
           type="text"
           class="w-full shadow-sm text-sm border-gray-300 rounded-md"
    >
@endunlessrole

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions