Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/Dev/FormPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Syntro\SilverstripeBootstrapForms\Forms\TextareaField;
use Syntro\SilverstripeBootstrapForms\Forms\TextField;
use Syntro\SilverstripeBootstrapForms\Forms\FieldGroup;
use Syntro\SilverstripeBootstrapForms\Forms\ReadonlyField;

/**
* demo controller
Expand Down Expand Up @@ -47,6 +48,7 @@ public function Form()
$emailfield = EmailField::create('emailfield', 'emailfield'),
$optionsetfield = OptionsetField::create('optionsetfield', 'optionsetfield', ['a' => 'value a', 'b' => 'value b']),
$phonefield = PhoneField::create('phonefield', 'phonefield'),
$readonlyfield = ReadonlyField::create('readonlyfield', 'readonlyfield'),
$textareafield = TextareaField::create('textareafield', 'textareafield'),
$textfield = TextField::create('textfield', 'textfield'),
);
Expand All @@ -57,6 +59,7 @@ public function Form()
$emailfield->addHolderClass('emailfieldholderclass')->addExtraClass('emailfieldextraclass');
$optionsetfield->addHolderClass('optionsetfieldholderclass')->addExtraClass('optionsetfieldextraclass');
$phonefield->addHolderClass('phonefieldholderclass')->addExtraClass('phonefieldextraclass');
$readonlyfield->addHolderClass('readonlyfieldholderclass')->addExtraClass('readonlyfieldextraclass');
$textareafield->addHolderClass('textareafieldholderclass')->addExtraClass('textareafieldextraclass');
$textfield->addHolderClass('textfieldholderclass')->addExtraClass('textfieldextraclass');

Expand Down
32 changes: 32 additions & 0 deletions src/Forms/ReadonlyField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Syntro\SilverstripeBootstrapForms\Forms;

use SilverStripe\Forms\ReadonlyField as BackendReadonlyField;

/**
* Frontend ReadonlyField
*
* @author Patrick Côté <patrick.cote@projektneptun.ch>
*/
class ReadonlyField extends BackendReadonlyField
{
use HolderClass;

/**
* Returns a readonly field.
*
* @param string $name name of the field
* @param null|string $title title of the field
* @param null|string $value value of the field
*
*
*/
function __construct($name, $title = null, $value = null)
{
$this->setFieldHolderTemplate('Syntro\\SilverstripeBootstrapForms\\Forms\\FormField_holder');
$this->setSmallFieldHolderTemplate('Syntro\\SilverstripeBootstrapForms\\Forms\\FormField_holder_small');
$this->setupDefaultHolderClasses();
parent::__construct($name, $title, $value);
}
}
15 changes: 14 additions & 1 deletion tests/RenderFormFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
use Syntro\SilverstripeBootstrapForms\Forms\CheckboxSetField;
use Syntro\SilverstripeBootstrapForms\Forms\DropdownField;
use Syntro\SilverstripeBootstrapForms\Forms\EmailField;
use Syntro\SilverstripeBootstrapForms\Forms\FieldGroup;
use Syntro\SilverstripeBootstrapForms\Forms\OptionsetField;
use Syntro\SilverstripeBootstrapForms\Forms\ReadonlyField;
use Syntro\SilverstripeBootstrapForms\Forms\TextareaField;
use Syntro\SilverstripeBootstrapForms\Forms\TextField;
use Syntro\SilverstripeBootstrapForms\Forms\FieldGroup;

/**
* Test the form fields generation
Expand Down Expand Up @@ -143,6 +144,18 @@ public function testPhoneFieldRendering()
$this->assertStringContainsString('<input type="tel" name="phonefield" class="phone form-control phonefieldextraclass" id="Form_Form_phonefield" />', $body);
}

public function testReadonlyFieldRendering()
{
$formPage = $this->objFromFixture(FormPage::class, 'page');
$formPage->copyVersionToStage('Stage', 'Live');

$page = $this->get('/form');
$body = $page->getBody();

$this->assertStringContainsString('<div id="Form_Form_readonlyfield_Holder" class="readonlyfieldholderclass">', $body);
$this->assertStringContainsString('<label class="form-label" for="Form_Form_readonlyfield">readonlyfield</label>', $body);
$this->assertStringContainsString('<span id="Form_Form_readonlyfield" class="readonly"></span>', $body);
}

/**
* testTextareaFieldRendering - description
Expand Down