Old data should come from failed validation, not a back button.
Sep 18, 2022
23
Level 10
Repopulate form data on back button browser
I am trying to repopulate my packages properly but that does not work very well. If i click the browser back button it always takes the default value 'small' but that should not be the case. The problem is if the packages are not properly repopulated the user books the wrong package.
I think this does not work x-data="{ package: '{{ old('package_type', 'small') }}' }
My code
<fieldset x-data="{ package: '{{ old('package_type', 'small') }}' }">
<legend class="text-base font-medium text-gray-900">Wähle Dein Paket</legend>
<div class="mt-4 grid grid-cols-1 gap-y-6 sm:grid-cols-3 sm:gap-x-4">
<!--
Checked: "border-transparent", Not Checked: "border-gray-300"
Active: "border-lime-500 ring-2 ring-lime-500"
-->
<label
:class="package == 'small' ? 'border-lime-500 ring-2 ring-lime-500' : 'border-gray-300'"
class="relative bg-white border rounded-lg shadow-sm p-4 flex cursor-pointer focus:outline-none">
<input type="radio" x-model="package" name="package_type" value="small"
class="sr-only" aria-labelledby="package-type-0-label"
:aria-checked="package == 'small'"
aria-describedby="package-type-0-description-0 package-type-0-description-1">
<span class="flex-1 flex">
<span class="flex flex-col">
<span id="package-type-0-label"
class="block text-sm font-medium text-gray-900">
Small </span>
<span id="package-type-0-description-0"
class="mt-1 flex items-center text-sm text-gray-500">Normale
Stellenauschreibung</span>
<span id="package-type-0-description-1"
class="mt-6 text-sm font-medium text-gray-900">{{ App\Service\Job\JobService::getEuroAmount(App\Service\Job\JobService::PACKAGE_TYPE_SMALL_PRICE) }}
€</span>
</span>
</span>
<!--
Not Checked: "invisible"
Heroicon name: solid/check-circle
-->
<svg class="h-5 w-5 text-lime-600"
:class="package == 'small' ? 'visible' : 'invisible'"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"
aria-hidden="true">
<path fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
clip-rule="evenodd" />
</svg>
<!--
Active: "border", Not Active: "border-2"
Checked: "border-lime-500", Not Checked: "border-transparent"
-->
<span
class="package == 'small' ? 'border border-lime-500' : 'border-2 border-transparent'"
class="absolute -inset-px rounded-lg border-2 pointer-events-none"
aria-hidden="true"></span>
</label>
<!--
Checked: "border-transparent", Not Checked: "border-gray-300"
Active: "border-lime-500 ring-2 ring-lime-500"
-->
<label
:class="package == 'medium' ? 'border-lime-500 ring-2 ring-lime-500' : 'border-gray-300'"
class="relative bg-white border rounded-lg shadow-sm p-4 flex cursor-pointer focus:outline-none">
<input type="radio" x-model="package" name="package_type" value="medium"
class="sr-only" aria-labelledby="package-type-1-label"
:aria-checked="package == 'medium'"
aria-describedby="package-type-1-description-0 package-type-1-description-1">
<span class="flex-1 flex">
<span class="flex flex-col">
<span id="package-type-1-label"
class="block text-sm font-medium text-gray-900">
Medium </span>
<span id="package-type-1-description-0"
class="mt-1 flex items-center text-sm text-gray-500">Stellenauschreibung
mit farblicher Hervorhebung</span>
<span id="package-type-1-description-1"
class="mt-6 text-sm font-medium text-gray-900">{{ App\Service\Job\JobService::getEuroAmount(App\Service\Job\JobService::PACKAGE_TYPE_MEDIUM_PRICE) }}
€</span>
</span>
</span>
<!--
Not Checked: "invisible"
Heroicon name: solid/check-circle
-->
<svg class="h-5 w-5 text-lime-600"
:class="package == 'medium' ? 'visible' : 'invisible'"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"
aria-hidden="true">
<path fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
clip-rule="evenodd" />
</svg>
<!--
Active: "border", Not Active: "border-2"
Checked: "border-lime-500", Not Checked: "border-transparent"
-->
<span
class="package == 'medium' ? 'border border-lime-500' : 'border-2 border-transparent'"
class="absolute -inset-px rounded-lg border-2 pointer-events-none"
aria-hidden="true"></span>
</label>
<!--
Checked: "border-transparent", Not Checked: "border-gray-300"
Active: "border-lime-500 ring-2 ring-lime-500"
-->
<label
:class="package == 'premium' ? 'border-lime-500 ring-2 ring-lime-500' : 'border-gray-300'"
class="relative bg-white border rounded-lg shadow-sm p-4 flex cursor-pointer focus:outline-none : relative bg-white border rounded-lg shadow-sm p-4 flex cursor-pointer focus:outline-none">
<input type="radio" x-model="package" name="package_type" value="premium"
class="sr-only" aria-labelledby="package-type-2-label"
:aria-checked="package == 'premium'"
aria-describedby="package-type-2-description-0 package-type-2-description-1">
<span class="flex-1 flex">
<span class="flex flex-col">
<span id="package-type-2-label"
class="block text-sm font-medium text-gray-900">
Premium </span>
<span id="package-type-2-description-0"
class="mt-1 flex items-center text-sm text-gray-500">Stellenauschreibung
mit farblicher Hervorhebung und besserem Ranking</span>
<span id="package-type-2-description-1"
class="mt-6 text-sm font-medium text-gray-900">{{ App\Service\Job\JobService::getEuroAmount(App\Service\Job\JobService::PACKAGE_TYPE_PREMIUM_PRICE) }}
€</span>
</span>
</span>
<!--
Not Checked: "invisible"
Heroicon name: solid/check-circle
-->
<svg class="h-5 w-5 text-lime-600"
:class="package == 'premium' ? 'visible' : 'invisible'"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"
aria-hidden="true">
<path fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
clip-rule="evenodd" />
</svg>
<!--
Active: "border", Not Active: "border-2"
Checked: "border-lime-500", Not Checked: "border-transparent"
-->
<span
class="package == 'premium' ? 'border border-lime-500' : 'border-2 border-transparent'"
class="absolute -inset-px rounded-lg border pointer-events-none"
aria-hidden="true"></span>
</label>
</div>
</fieldset>
Level 63
@SmokeTM Then why don't you put the datas in the session as I suggested you.
I think that there is a big confusion between what help you need and what we understand to help you.
1 like
Please or to participate in this conversation.