diff --git a/Time.php b/Time.php new file mode 100644 index 00000000..6b9165e4 --- /dev/null +++ b/Time.php @@ -0,0 +1,22 @@ +` element of type "time" are let the user enter a time (hour, minute, second, and fraction of a + * second). + * + * @link https://html.spec.whatwg.org/multipage/input.html#time-state-(type=time) + * @link https://developer.mozilla.org/docs/Web/HTML/Element/input/time + */ +final class Time extends DateTimeInputField +{ + protected function getInputType(): string + { + return 'time'; + } +} diff --git a/src/Field/Time.php b/src/Field/Time.php new file mode 100644 index 00000000..6b9165e4 --- /dev/null +++ b/src/Field/Time.php @@ -0,0 +1,22 @@ +` element of type "time" are let the user enter a time (hour, minute, second, and fraction of a + * second). + * + * @link https://html.spec.whatwg.org/multipage/input.html#time-state-(type=time) + * @link https://developer.mozilla.org/docs/Web/HTML/Element/input/time + */ +final class Time extends DateTimeInputField +{ + protected function getInputType(): string + { + return 'time'; + } +} diff --git a/src/LoadMultipleTrait.php b/src/LoadMultipleTrait.php new file mode 100644 index 00000000..b341bb12 --- /dev/null +++ b/src/LoadMultipleTrait.php @@ -0,0 +1,42 @@ +getFormName(); + } + + if ($formName !== '') { + $data = $data[$formName]; + } + + $success = true; + + foreach (array_keys($data) as $i) { + /* @var \Yiisoft\Form\FormModelInterface $model */ + $model = clone $this; + + if ($model->load($data[$i], '') === true) { + $this->models[] = $model; + } else { + $this->models[] = $success = false; + } + } + + return $success; + } + + public function getModels(): array + { + return $this->models; + } +} diff --git a/tests/MultipleFormModelTest.php b/tests/MultipleFormModelTest.php new file mode 100644 index 00000000..e237a703 --- /dev/null +++ b/tests/MultipleFormModelTest.php @@ -0,0 +1,124 @@ +getFormName(); + + $data = [ + $formName => [ + [ + 'attribute1' => 'b5HhRBieacLZki2H', + 'attribute2' => 'eu3VXDpwvvyoahwNAjPmjYV7PgCEZ9pTAWAf', + 'attribute3' => 'ym8ES3nDhxN4', + 'attribute4' => 'CupHZ4Ljzeym8q8Hmu8', + ], + [ + 'attribute1' => 's8rcuBHjZ4MXEkGU2YToFGz9XTADyg4j8ibZ', + 'attribute2' => 'eDruLPmPkALRE7qUyhDapJZTTnE2A', + 'attribute3' => '2f6ot3S5f8T7tNm5', + 'attribute4' => 'rYNM4jfZ7kFCN6A4i7apSMFPxq', + ], + [ + 'attribute1' => '64brF469aKhY', + 'attribute2' => 'J3BSpg4rVY6mVq5cTu', + 'attribute3' => 'h8VpgtLbwz6WyUhCLgFgg5wkdqtmmBy5HE5U', + 'attribute4' => '6yDHpqf357fEcKsYeJz', + ], + [ + 'attribute1' => 'Mqx6LL78mysscsaHLhSSM46Uht46tdAvaejs', + 'attribute2' => '7PqV94mzGL2tP', + 'attribute3' => 'K7ZvDNkEv4cwsPpTEpBsJEu7', + 'attribute4' => 'CtsAPJQnUUCgKFGfvQ6C', + ], + [ + 'attribute1' => '49xuodLX3XPb9LueLSUq7GbhdRa3aw', + 'attribute2' => '2MHboYwmBLXyWYPJoXeoKLjVS', + 'attribute3' => 'p6AJiq3NQsW4dwcKAz', + 'attribute4' => 'JetmdpKiVXMYBs3CLvQb7qEvyQDFXELDAeCb', + ], + ], + ]; + + $this->assertTrue($form->loadMultiple($data)); + + $models = $form->getModels(); + + $this->assertCount(count($data[$formName]), $models); + + foreach ($models as $i => $model) { + $this->assertInstanceOf(LoadMultipleForm::class, $model); + $this->assertSame($data[$formName][$i], $model->getData()); + } + } + */ + + public function testLoadFailedForm(): void + { + $form = new LoadMultipleForm(); + $formName = $form->getFormName(); + + $data = [ + $formName => [ + [ + 'attribute1' => 'b5HhRBieacLZki2H', + 'attribute2' => 'eu3VXDpwvvyoahwNAjPmjYV7PgCEZ9pTAWAf', + 'attribute3' => 'ym8ES3nDhxN4', + 'attribute4' => 'CupHZ4Ljzeym8q8Hmu8', + ], + [ + 'attribute1' => 's8rcuBHjZ4MXEkGU2YToFGz9XTADyg4j8ibZ', + 'attribute2' => 'eDruLPmPkALRE7qUyhDapJZTTnE2A', + 'attribute3' => '2f6ot3S5f8T7tNm5', + 'attribute4' => 'rYNM4jfZ7kFCN6A4i7apSMFPxq', + ], + [ + 'attribute1' => '64brF469aKhY', + 'attribute2' => 'J3BSpg4rVY6mVq5cTu', + 'attribute3' => 'h8VpgtLbwz6WyUhCLgFgg5wkdqtmmBy5HE5U', + 'attribute4' => '6yDHpqf357fEcKsYeJz', + ], + [ + // empty data to cause loading failure + ], + [ + 'attribute1' => '49xuodLX3XPb9LueLSUq7GbhdRa3aw', + 'attribute2' => '2MHboYwmBLXyWYPJoXeoKLjVS', + 'attribute3' => 'p6AJiq3NQsW4dwcKAz', + 'attribute4' => 'JetmdpKiVXMYBs3CLvQb7qEvyQDFXELDAeCb', + ], + ], + ]; + + $this->assertFalse($form->loadMultiple($data)); + + $models = $form->getModels(); + + $this->assertCount(count($data[$formName]), $models); + + foreach ($models as $i => $model) { + if (empty($data[$formName][$i])) { + $this->assertFalse($model); + } else { + $this->assertInstanceOf(LoadMultipleForm::class, $model); + $this->assertSame($data[$formName][$i], $model->getData()); + } + } + } +} \ No newline at end of file diff --git a/tests/TestSupport/Form/LoadMultipleForm.php b/tests/TestSupport/Form/LoadMultipleForm.php new file mode 100644 index 00000000..1ca458b3 --- /dev/null +++ b/tests/TestSupport/Form/LoadMultipleForm.php @@ -0,0 +1,18 @@ +