Skip to content
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

fix(navigate): fix cache session issue not update after submit completed #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azmanabdlh/gargantua",
"version": "1.0.0",
"version": "1.1.0",
"description": "Minimalist form wizard library.",
"keywords": ["library", "form wizard"],
"license": "MIT",
Expand Down
18 changes: 3 additions & 15 deletions example/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,15 @@
<div class="flex mb-2 space-x-2 rtl:space-x-reverse">
<div>
<label for="code-1" class="sr-only">First code</label>
<input type="text" maxlength="1" data-focus-input-init data-focus-input-next="code-2" id="code-1" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
<input type="text" maxlength="1" data-focus-input-init data-focus-input-next="code-2" id="code-1" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" />
</div>
<div>
<label for="code-2" class="sr-only">Second code</label>
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-1" data-focus-input-next="code-3" id="code-2" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-1" data-focus-input-next="code-3" id="code-2" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" />
</div>
<div>
<label for="code-3" class="sr-only">Third code</label>
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-2" data-focus-input-next="code-4" id="code-3" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
</div>
<div>
<label for="code-4" class="sr-only">Fourth code</label>
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-3" data-focus-input-next="code-5" id="code-4" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
</div>
<div>
<label for="code-5" class="sr-only">Fifth code</label>
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-4" data-focus-input-next="code-6" id="code-5" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
</div>
<div>
<label for="code-6" class="sr-only">Sixth code</label>
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-5" id="code-6" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-2" data-focus-input-next="code-4" id="code-3" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" />
</div>
</div>
<p id="helper-text-explanation" class="mt-2 text-sm text-gray-500 dark:text-gray-400">Please introduce the 6 digit code we sent via email.</p>
Expand Down
23 changes: 19 additions & 4 deletions src/CookieSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ private function makePages(Node $node): void {
$pages = [];
while (true) {
$key = $node->data->pageName();
$pages[$key] = [];
$pages[$key] = [
"last" => !$node->canNext(),
"beginning" => !$node->canBack(),
];

if ($node->canBack()) {
$prevNode = $node->prev;
Expand All @@ -59,17 +62,29 @@ private function getPage(string $key): array {
return isset($this->pages[$key]) ? $this->pages[$key] : [];
}

private function getCookie(): string {
return $this->request->cookies->get(self::CurrPageKey) ?? "";
}

public function get(): string {
$currPageKey = $this->request->cookies->get(self::CurrPageKey) ?? "";
$currPageKey = $this->getCookie();

if ($currPageKey == "") {
return "";
}

$curPage = $this->getPage($currPageKey);

if ($this->request->onSubmitted() && isset($curPage["next"])) {
$currPageKey = $curPage["next"];
if ($this->request->onSubmitted()) {
if (isset($curPage["next"])) {
$currPageKey = $curPage["next"];
}

if ($curPage["last"] == 1) {
$head = array_filter($this->pages, fn($page) => $page["beginning"] == 1);
$key = array_keys($head)[0];
$currPageKey = $key;
}
}

if ($this->request->onBack() && isset($curPage["prev"]) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function capture(array $cable = []): void {

$this->emitter->emit(Event::RequestSubmit, $page, $this->request);

$isCompleted = !$node->canNext();
$isCompleted = $node->canNext();

if ($node->canNext()) {
$page = $node->next->data;
Expand Down