Skip to content

Commit

Permalink
updating example
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobg committed Sep 7, 2021
1 parent 9a95704 commit 1d24a1a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 64 deletions.
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// For example, this builds HTML using Bootstrap as CSS and the Vue framework.
$composer = FrameworkComposer::create(['HTML', 'Bootstrap']);

// in real code you would pre-generate this and cache instead of runtime.
$model = Model::fromStruct(modelData());
// get your model data.
$model = modelData();

// get a button dynamically
$submitButton = $composer->element(
Expand Down
125 changes: 64 additions & 61 deletions model.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

use Formularium\Datatype;
use Formularium\Datatype\Datatype_string;
use Formularium\Field;
use Formularium\Frontend\HTML\Renderable\Renderable_number;
use Formularium\Frontend\HTML\Renderable\Renderable_string;
use Formularium\Model;
use Formularium\Renderable;
use Formularium\Validator\Max;
use Formularium\Validator\MaxLength;
Expand All @@ -13,69 +16,69 @@
require('./Datatype_aaaaa.php');
require('./Renderable_aaaaa.php');

function modelData() {
function modelData(): Model
{
// build the model from data description. You can use a JSON file as well.
$modelData = [
'name' => 'TestModel',
'fields' => [
'myString' => [
'datatype' => 'string',
'validators' => [
MinLength::class => [
'value' => 3,
],
MaxLength::class => [
'value' => 10,
],
Datatype::REQUIRED => [
'value' => true,
]
],
'renderable' => [
Renderable::LABEL => 'This is some string',
Renderable::COMMENT => 'At least 3 characters but no more than 10',
Renderable_string::NO_AUTOCOMPLETE => true,
Renderable::PLACEHOLDER => "Type here",
Renderable::ICON_PACK => 'fas',
Renderable::ICON => 'fa-check'
]
$modelData = new Model(
'TestModel',
);
$modelData->appendField(new Field(
'myString',
Datatype_string::class,
[
Renderable::LABEL => 'This is some string',
Renderable::COMMENT => 'At least 3 characters but no more than 10',
Renderable_string::NO_AUTOCOMPLETE => true,
Renderable::PLACEHOLDER => "Type here",
Renderable::ICON_PACK => 'fas',
Renderable::ICON => 'fa-check'
],
[
MinLength::class => [
'value' => 3,
],
'someInteger' => [
'datatype' => 'integer',
'validators' => [
Min::class => [
'value' => 4,
],
Max::class => [
'value' => 30,
],
Datatype::REQUIRED => [
'value' => true,
]
],
'renderable' => [
Renderable_number::STEP => 2,
Renderable_string::NO_AUTOCOMPLETE => true,
Renderable::LABEL => 'Some integer',
Renderable::COMMENT => 'Between 4 and 30',
Renderable::PLACEHOLDER => "Type here"
]
MaxLength::class => [
'value' => 10,
],
'myaaaaa' => [
'datatype' => 'aaaaa',
'validators' => [
Datatype::REQUIRED => [
'value' => true,
]
],
'renderable' => [
Renderable::LABEL => 'This is a custom datatype',
Renderable::COMMENT => 'Fill this with aaaaa to validate properly',
Renderable_string::NO_AUTOCOMPLETE => true,
Renderable::PLACEHOLDER => "Type aaaaa here"
]
Datatype::REQUIRED => [
'value' => true,
]
],
))->appendField(new Field(
'someInteger',
'integer',
[
Renderable_number::STEP => 2,
Renderable_string::NO_AUTOCOMPLETE => true,
Renderable::LABEL => 'Some integer',
Renderable::COMMENT => 'Between 4 and 30',
Renderable::PLACEHOLDER => "Type here"
],
[
Min::class => [
'value' => 4,
],
]
];
Max::class => [
'value' => 30,
],
Datatype::REQUIRED => [
'value' => true,
]
],
))->appendField(new Field(
'myaaaaa',
'aaaaa',
[
Renderable::LABEL => 'This is a custom datatype',
Renderable::COMMENT => 'Fill this with aaaaa to validate properly',
Renderable_string::NO_AUTOCOMPLETE => true,
Renderable::PLACEHOLDER => "Type aaaaa here"
],
[
Datatype::REQUIRED => [
'value' => true,
]
],
));
return $modelData;
}
}
3 changes: 2 additions & 1 deletion post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

// set your framework composition
$framework = FrameworkComposer::create(['HTML', 'Bootstrap']);

// build the model
$model = Model::fromStruct(modelData());
$model = modelData();

// validate some data
$validation = $model->validate($_POST);
Expand Down

0 comments on commit 1d24a1a

Please sign in to comment.