AdamWathan\Form\Elements\Checkbox::defaultToUnchecked PHP Method

defaultToUnchecked() public method

public defaultToUnchecked ( )
    public function defaultToUnchecked()
    {
        if (!isset($this->checked) && is_null($this->oldValue)) {
            $this->uncheck();
        }
        return $this;
    }

Usage Example

Example #1
0
 public function testDefaultToUnchecked()
 {
     $checkbox = new Checkbox('above_18');
     $expected = '<input type="checkbox" name="above_18" value="1">';
     $result = $checkbox->defaultToUnchecked()->render();
     $this->assertEquals($expected, $result);
     $checkbox = new Checkbox('above_18');
     $expected = '<input type="checkbox" name="above_18" value="1" checked="checked">';
     $result = $checkbox->defaultToUnchecked()->check()->render();
     $this->assertEquals($expected, $result);
     $checkbox = new Checkbox('above_18');
     $expected = '<input type="checkbox" name="above_18" value="1" checked="checked">';
     $result = $checkbox->check()->defaultToUnchecked()->render();
     $this->assertEquals($expected, $result);
 }