summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/html/src/FormElement/SubFormElement.php
blob: 5e0f77e06baec08cc14df13fee8890d1012af891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

namespace ipl\Html\FormElement;

use ipl\Html\Attributes;

class SubFormElement extends BaseFormElement
{
    use FormElements;

    protected $tag = 'div';

    protected $defaultAttributes = [
        'class' => 'ipl-subform'
    ];

    public function getValue($name = null)
    {
        if ($name === null) {
            return $this->getValues();
        } else {
            return $this->getElement($name)->getValue();
        }
    }

    public function setValue($value)
    {
        $this->populate($value);

        return $this;
    }

    public function isValid()
    {
        foreach ($this->getElements() as $element) {
            if (! $element->isValid()) {
                return false;
            }
        }

        return true;
    }

    public function hasSubmitButton()
    {
        return true;
    }

    protected function registerValueCallback(Attributes $attributes)
    {
        $attributes->registerAttributeCallback(
            'value',
            null,
            [$this, 'setValue']
        );
    }
}