Skip to content
Closed
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 src/Forms/JsDrivers/Alpine.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function renderAlpineXData($xData, $alpineScope)
protected function getAlpineXDataKey($fieldHandle, $alpineScope)
{
return is_string($alpineScope)
? "{$alpineScope}.{$fieldHandle}"
? "{$alpineScope}['{$fieldHandle}']"
: $fieldHandle;
}

Expand Down
22 changes: 11 additions & 11 deletions tests/Tags/Form/FormCreateAlpineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public function it_dynamically_renders_text_field_x_model()
];

$this->assertFieldRendersHtml(['<input type="text" name="name" value="" x-model="name">'], $config, [], ['js' => 'alpine']);
$this->assertFieldRendersHtml(['<input type="text" name="name" value="" x-model="my_form.name">'], $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml(['<input type="text" name="name" value="" x-model="my_form[\'name\']">'], $config, [], ['js' => 'alpine:my_form']);
}

/** @test */
Expand All @@ -307,7 +307,7 @@ public function it_dynamically_renders_textarea_field_x_model()
];

$this->assertFieldRendersHtml(['<textarea name="comment" rows="5" x-model="comment"></textarea>'], $config, [], ['js' => 'alpine']);
$this->assertFieldRendersHtml(['<textarea name="comment" rows="5" x-model="my_form.comment"></textarea>'], $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml(['<textarea name="comment" rows="5" x-model="my_form[\'comment\']"></textarea>'], $config, [], ['js' => 'alpine:my_form']);
}

/** @test */
Expand All @@ -329,9 +329,9 @@ public function it_dynamically_renders_checkboxes_field_x_model()
$this->assertFieldRendersHtml(['<input type="checkbox" name="fav_animals[]" value="rat" x-model="fav_animals">'], $config, [], ['js' => 'alpine']);
$this->assertFieldRendersHtml(['<input type="checkbox" name="fav_animals[]" value="armadillo" x-model="fav_animals">'], $config, [], ['js' => 'alpine']);

$this->assertFieldRendersHtml(['<input type="checkbox" name="fav_animals[]" value="cat" x-model="my_form.fav_animals">'], $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml(['<input type="checkbox" name="fav_animals[]" value="rat" x-model="my_form.fav_animals">'], $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml(['<input type="checkbox" name="fav_animals[]" value="armadillo" x-model="my_form.fav_animals">'], $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml(['<input type="checkbox" name="fav_animals[]" value="cat" x-model="my_form[\'fav_animals\']">'], $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml(['<input type="checkbox" name="fav_animals[]" value="rat" x-model="my_form[\'fav_animals\']">'], $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml(['<input type="checkbox" name="fav_animals[]" value="armadillo" x-model="my_form[\'fav_animals\']">'], $config, [], ['js' => 'alpine:my_form']);
}

/** @test */
Expand All @@ -353,9 +353,9 @@ public function it_dynamically_renders_radio_field_x_model()
$this->assertFieldRendersHtml(['<input type="radio" name="fav_animal" value="rat" x-model="fav_animal">'], $config, [], ['js' => 'alpine']);
$this->assertFieldRendersHtml(['<input type="radio" name="fav_animal" value="armadillo" x-model="fav_animal">'], $config, [], ['js' => 'alpine']);

$this->assertFieldRendersHtml(['<input type="radio" name="fav_animal" value="cat" x-model="my_form.fav_animal">'], $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml(['<input type="radio" name="fav_animal" value="rat" x-model="my_form.fav_animal">'], $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml(['<input type="radio" name="fav_animal" value="armadillo" x-model="my_form.fav_animal">'], $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml(['<input type="radio" name="fav_animal" value="cat" x-model="my_form[\'fav_animal\']">'], $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml(['<input type="radio" name="fav_animal" value="rat" x-model="my_form[\'fav_animal\']">'], $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml(['<input type="radio" name="fav_animal" value="armadillo" x-model="my_form[\'fav_animal\']">'], $config, [], ['js' => 'alpine:my_form']);
}

/** @test */
Expand Down Expand Up @@ -385,7 +385,7 @@ public function it_dynamically_renders_select_field_x_model()
$this->assertFieldRendersHtml($expected, $config, [], ['js' => 'alpine']);

$expectedScoped = [
'<select name="favourite_animal" x-model="my_form.favourite_animal">',
'<select name="favourite_animal" x-model="my_form[\'favourite_animal\']">',
'<option value>Please select...</option>',
'<option value="cat">Cat</option>',
'<option value="armadillo">Armadillo</option>',
Expand All @@ -409,7 +409,7 @@ public function it_dynamically_renders_asset_field_x_model()
];

$this->assertFieldRendersHtml('<input type="file" name="cat_selfie" x-model="cat_selfie">', $config, [], ['js' => 'alpine']);
$this->assertFieldRendersHtml('<input type="file" name="cat_selfie" x-model="my_form.cat_selfie">', $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml('<input type="file" name="cat_selfie" x-model="my_form[\'cat_selfie\']">', $config, [], ['js' => 'alpine:my_form']);
}

/** @test */
Expand All @@ -423,7 +423,7 @@ public function it_dynamically_renders_field_with_fallback_to_default_partial_x_
];

$this->assertFieldRendersHtml('<input type="text" name="custom" value="" x-model="custom">', $config, [], ['js' => 'alpine']);
$this->assertFieldRendersHtml('<input type="text" name="custom" value="" x-model="my_form.custom">', $config, [], ['js' => 'alpine:my_form']);
$this->assertFieldRendersHtml('<input type="text" name="custom" value="" x-model="my_form[\'custom\']">', $config, [], ['js' => 'alpine:my_form']);
}

private function jsonEncode($data)
Expand Down