Code Monkey home page Code Monkey logo

aura.input's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aura.input's Issues

Add an addRule

I would like to add an addRule, so that we can add multiple error messages.

This is from the discussion in irc http://colabti.org/irclogger/irclogger_log/auraphp?date=2013-03-13 . For a quick reference I am keeping.

17:04   harikt  1 qn , currently the filter can only hold one filter for the field, why not add it for multiple ones?
17:04   harikt  I mean for the Aura.Input Filter
17:04   harikt  not Aura.Filter
17:14   pmjones     oh, so, on Aura.Input filter, it's intended as a placeholder for a "real" filter system
17:14   pmjones     it's the simplest thing that can possibly work as a filter system, but it's clearly not very robust
17:15   pmjones     and doing it this way means anyone can add any filter system, and add on the very basic Aura.Input setRule() method
17:16   pmjones     hope that helps explain
17:29   harikt  not sure whether you understood me clearly .
17:30   harikt  pmjones, if you look into this https://github.com/harikt/Aura.Input/blob/6456c130e9c7007badadfd8630102c29101a9419/src/Aura/Input/Filter.php
17:30   harikt  You can see the rules field I added as array .
17:31   harikt  I agree it is just a place holder, but it can act more powerful like adding more filters than a single rule
17:31   harikt  Try adding setRule twice on a field.
17:32   harikt  only the last one will be taken , this way we can add multiple rules
18:20   pmjones     harikt: yes, that's correct, only the last one gets used.
18:20   pmjones     it's "set" rule, not "add" rule
18:21   pmjones     and because the rule is a closure, it means you can add any logic you want, meaning you can add multiple checks inside the closure
18:21   pmjones     thus, there's no need for multiple rules when using setRule()
18:21   pmjones     you add whatever rules you want inside the closure

Yes I noticed the set and add, so I guess we need a addRule for the setRule can only set one error message. But it will be good if we have multiple error messages.

I also agree with your point of multiple rules inside the closure, but error message is same makes me feel not a good idea.

Say you need to check the max string length, and whether it is string. So the user should know from the error what the error is. Not just it is not a string or the entered value is incorrect. But a clear understanding of what made wrong.

I also agree this is a simple filter and users can use other filtering / validation system. But I prefer to add it in this simple filter. It is not that much ;-)

Regarding "Add an addRule"

Regarding #13, I'm wondering if we could discuss this again?

I feel add an additional addRule method would be really useful and would avoid developers having to write their own class that extends Filter or implements FilterInterface.

I don't think that having two method, setRule and addRule, would be confusing for developers.

Also, Filter currently supports multiple messages per Field, so I don't think there will be any BC breaking with the messages.

What are your current thoughts?

Cheers
Stephen

Good to have a solution, probably in Framework?

Some times we will be having input of

<input type="text" name="title[]" id="title0" value="some value" />

In this case the filter can be

$filter->addSoftRule('title', $filter::IS, 'alnum');

Which needs to be validated for all the title array. Rather than we writing title0 it is always wise to have the title[] field.

We want to find a way that passing the value to filter can be addressed. Not sure whether it should come in Aura.Filter or Aura.Input

There should be a way to set error messages for the field

I was working with a special requirement and I feel there should be a way to set the error messages for the field.

The reason is some validators are validating the model like username already exists in the database, and it will be nice if we can set the error messages to the corresponding field name.

I will work on both the Aura.Input and Aura.Filter to have a method setMessages($field = null) .

What do you think? Go with it ?

Need hasField

It will be good to have hasField method for when we are adding a AntoCsrf class, if it is not authenticated the field __csrf_token will not be added and it will thow an exception

Uncaught exception 'Aura\Input\Exception\NoSuchInput' with message '__csrf_token'

GetItrator() throw NoSuchInput exception

Form::getIterator() doesn't work.

$form = new Form(new Builder, new Filter);
        $form->setField('foo');
        $form->setField('bar');

        $iterator = $form->getIterator();

'Aura\Input\Exception\NoSuchInput : fields' exception thrown with this code.

What about automatic id

I noticed currently when the id is not specified the id field is null, what about assigning the same name for the id, if it is not specified..

I feel this is good option else we may want to specify at many times,

FormFactory

Can we add a FormFactory to the default.php

<?php
$di->params['Aura\Input\FormFactory'] = [
    // a map of form names to form factories
    'map' => [
        'map-name' => $di->newFactory('classes'),
    ],
];

$di->set('form_factory', $di->lazyNew('Aura\Input\FormFactory'));

$di->setter['Aura\Framework\Web\Controller\AbstractPage']['setFormFactory'] = $di->lazyGet('form_factory');

and the FormFactory as

<?php
namespace Aura\Input;

class FormFactory
{
    protected $map = [];

    public function __construct($map = [])
    {
        $this->map = $map;
    }

    public function newInstance($name)
    {
        if (! array_key_exists($name, $this->map)) {
            throw new \Exception("No form with the name found");
        }
        $factory = $this->map[$name];
        $form = $factory();
        return $form;
    }
}

That way everyone don't need to spend more time on making things to work. What do you think ? I can give a PR if so.

Fieldsets and collections

I'm evaluating aura for using it as a form component. It looks very promising. Thanks for your work!

I am struggling with fieldsets at the moment. I would like to use them to group my input fields into them and render a html fieldset. Setting it up is all fine, rendering as well. But I struggle with filling the field data.

  • If I render the fieldset as fieldset, the name of the fieldset wont be set as input var, so the fields of the fieldset does not get filled
  • If I render a hidden field for the fieldset, Aura.Input tries to fill the children as well. But it does not pass the data array, only the given string.

Did I miss something? Is there another way? Or what is the purpose of the fieldsets/collections?

Add an empty row to the collection

I really like the idea of collections and fieldsets in Aura, but I struggle at some points. Here is another one.

At the moment an collection can only be rendered if any data is filled in (by a model, by post etc.). It would be great add an empty fieldset row or at least to get the fieldset so I could create empty rows in the View of the collection.

public function addEmptyFieldset()
{
    $index = $this->count();
    $new = $this->newFieldset($index);
    $this->fieldsets[$index] = $new;

    return $new;
}

Why no setOptions on Fieldset?

Hello,

I'm dealing with a situation where I need to use $fieldset->options during validation. There's no way to inject it in through the factory, and no way to call $fieldset->setOptions(). For example:

class PriceRangeFieldset extends Fieldset {

    public function init() {
        $this->setField('low', 'number');
        $this->setField('high', 'number');

        $this->addRule('low', "The {$this->options['label']} low field only accepts digits.", function ($value) {
            return $value === null || $value === '' || ctype_digit($value);
        });

        $this->addRule('high', "The {$this->options['label']} high field only accepts digits.", function ($value) {
            return $value === null || $value === '' || ctype_digit($value);
        });
    }

}

And in the form:

class MyForm extends Form {

    public function init() {
        $this->setFieldset('design', 'price-range')
            ->setOptions(['label' => 'Design']);

        $this->setFieldset('development', 'price-range')
            ->setOptions(['label' => 'Development']);
    }

}

Was there a choice to prevent this use-case?

getValues

I am mixing the packages, sorry. But consider

$data = $_POST;
$form->fill($data);
$form->filter();

In this case we get a filtered data of the fields, it have. But in many cases it will be like $_POST having more values. So I feel there is a need for $form->getValues() or something like that which we only get the values of the fields it have, removing the extra post values.

What do you think ?

getField and getFields

I feel there is an inconsistency in the output provided by both.

For eg ๐Ÿ‘

    public function getField($name)
    {
        $value = isset($this->values[$name])
               ? $this->values[$name]
               : null;

        return ['name' => $name]
             + $this->fields->get($name)->asArray()
             + ['value' => $value];
    }

    public function getFields()
    {
        return $this->fields;
    }

The getField returns an array and getFields returns a FieldCollection .

Wondering whether it is good to have return Field itself than an array for getField .

https://github.com/auraphp/Aura.Input/blob/develop/src/Aura/Input/Form.php#L92

On integrating Filter and Input. Are we sure?

For some time I have been excited about the Filter_Interface package, and the
ability to integrate Input and Filter. However, now I am questioning if
that's right.

Filter is for validating and sanitizing. That's my domain logic, right?
Input is mainly about describing (HTML) inputs. That's presentation, right?

I don't need to inject an object into my domain that describe the inputs. I need
to take the output of my domain (errors), and pass them to the thing describing
the UI, no?

// Domain
class CreateThing
{
    //...
    public function __invoke(array $input)
    {
        $this->payload->setInput($input);

        // No reason i need to know about describing HTML UI stuff here
        if (! $this->filter->apply($input)) {
            $failures = $this->filter->getFailures();
            return $this->payload
                ->setStatus(Status::INVALID)
                ->setOutput($failures);
        }

        //...
    }
}

// Responder
class CreateThingResponder
{
    //...
    protected function invalid()
    {
        $this->response = $this->response->withStatus(HTTP_STATUS::INVALID);

        $this->view->setScript('thing/create')
        $this->view->addData(
            [
                'input'  => $this->payload->getInput(),
                'errors' => $this->payload->getOutput()
            ]
        );
        $this->renderViewToResponse();
    }
}

// view: create/thing.php

$form = new CreateThingForm;

if ($this->input) {
    $form->setInput($this->input);
}

if ($this->errors) {
    $form->setErrors($this->errors);
}

// This is the only time i need information describing the HTML UI
echo $this->render('form', ['form' => $form]);

Are we sure Input needs to know about validation outside of just understanding
that errors exist?

Since Input has been stuck in 1.x land, here's how I've been doing things for a little bit:
https://github.com/jnjxp/jnjxp.form

Thoughts?
Maybe I'm wrong, but I kinnda think Input should just deal with describing UI
stuff, and not know about validation and sanitization logic.

Starting 3.x

Hi all,

I am currently cleaning up the Aura.Input 1.x branch in order to move it to 3.x.

Are there any feature request / problems we need to resolve ?

Please create issues or discuss here.

Thank you

What is the future of this project?

What is the future of this project? In my opinion, it is feature complete and only needs to have the latest versions of PHP (7.3, 7.4 & 8.0 as of this writing) tested via travis or Github Actions to ensure it continues to work with the currently supported version of PHP. Will anyone be updating the CI tests for this project?

May be a isSuccess flag

Hi Paul,

I was working on form, and submissions lately with the ADR .

The form is injected to the Domain\Contact . Now when the request method is post the form is calling fill() and filter() .

We are setting the form back to the responder.

One thing probably you may mention will be keep the get and post Actions different. But to me it seems duplicating so much efforts.

I was thinking whether it is good to have a isSuccess() method and return true / false if a check on filter() is called. Else nothing is returned.

Another thing is getMessages() can be checked for errors, but if the form is not submitted the getMessages() empty and that doesn't means it is success and display the message, the way isSuccess help us is recognize whether a call to filter has happened rather the user testing again on responder with certain flags set when a request is submitted etc.

Interested to hear your thoughts.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.