Giter Site home page Giter Site logo

contributte / forms Goto Github PK

View Code? Open in Web Editor NEW
10.0 6.0 4.0 79 KB

:sparkles: Extra contrib to nette/forms (@nette)

Home Page: https://contributte.org/packages/contributte/forms.html

License: MIT License

PHP 92.03% Makefile 0.40% HTML 7.57%
nette-framework forms inputs contributte email nette

forms's Introduction

Website ๐Ÿš€ contributte.org | Contact ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป f3l1x.io | Twitter ๐Ÿฆ @contributte

Usage

To install latest version of contributte/forms use Composer.

composer require contributte/forms

Documentation

For details on how to use this package, check out our documentation.

Versions

State Version Branch Nette PHP
dev ^0.6 master 3.0+ >=7.2
stable ^0.5 master 3.0+ >=7.2
stable ^0.3 master 2.4 >=7.1

Development

See how to contribute to this package. This package is currently maintained by these authors.


Consider to support contributte development team. Also thank you for using this package.

forms's People

Contributors

f3l1x avatar gappa avatar mabar avatar martinmystikjonas avatar petrparolek avatar roman3349 avatar vody105 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

forms's Issues

Split form factory

Split it into StandaloneFormFactory a FormFactory (Nette\App\UI\Form)

Date is not updated with Doctrine ORM

Version: dev-master

Bug Description

I used https://github.com/FreezyBee/DoctrineFormMapper. In DB I have null in date column. If is filled date in form date is not updated in DB (NULL persists).

Steps To Reproduce

Example presenter:

    use FreezyBee\DoctrineFormMapper\DoctrineFormMapper;
    use FreezyBee\DoctrineFormMapper\IComponentMapper;
    
    class SomePresenter extends Presenter
    {
        /** @var DoctrineFormMapper @inject */
        public $mapper;
    
        /** @var EntityRepository @inject */
        public $articlesRepository;
        
        protected function createComponentForm()
        {
            $form = new Form;
    
            // Column
            $form->addText('name');
    
            // ManyToOne
            $form->addSelect('author')
                // order items
                ->setOption(IComponentMapper::ITEMS_ORDER, ['age' => 'ASC'])
                // filter items
                ->setOption(IComponentMapper::ITEMS_FILTER, ['age' => 0])
                // filter items by callback
                ->setOption(IComponentMapper::ITEMS_FILTER, function(QueryBuilder $qb) {
                    $qb->andWhere('entity.age != 0')
                })
                // custom select label renderer
                ->setOption(IComponentMapper::ITEMS_TITLE, function (Author $author) {
                    return $author->getName() . ' - ' . $author->getAge();
                });
    
            // ManyToOne
            $form->addRadioList('tags')
                ->setOption(IComponentMapper::ITEMS_TITLE, 'name');
    
    
            // ManyToMany
            $form->addMultiSelect('users')
                ->setOption(IComponentMapper::ITEMS_TITLE, 'username');
    
            // ManyToMany
            // btw you can define items and then ITEMS_TITLE is not required
            $form->addCheckboxList('countries', 'Countries', [1 => 'CZ', 2 => 'SK']);
    
    
            // A) create new entity
            $article = new Article;
    
            // B) load entity from db
            $article = $this->articlesRepository->find(1);
            
            // C) create new entity by class name - see point INFO below
            $article = Article::class;
            
            // load data from entity to form
            $this->mapper->load($article, $form);
    
            $form->onSuccess[] = function (Form $form) use ($article) {
                
                // save (map) data from form to entity - without flush!!!
                $articleEntity = $this->mapper->save($article, $form);
                
                // INFO - if article was classname, mapper create new instance
                // $articleEntity is instanceof Article
                
                // flush data...
                $em = $this->mapper->getEntityManager();
                $em->persist($articleEntity)
                $em->flush();
            };
    
            return $form;
        }
    }

Example entity:

<?php

declare(strict_types=1);

namespace App\Entities;

use DateTime;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class TestDate
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    private int $id = 0;

    /**
     * @ORM\Column(type="string")
     */
    private string $title;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private ?DateTime $date;

    public function getId(): int
    {
        return $this->id;
    }

    public function getTitle(): int
    {
        return $this->title;
    }

    public function getDate(): DateTime
    {
        return $this->date;
    }

   public function setTitle(string $title): void
   {
      $this->title = $title;
   }

   public function setDate(DateTime $date): void
   {
      $this->date = $date;
   }
}

Expected Behavior

Save correct data into DB

Possible Solution

PR: #33

Improvement suggestions

Hi once again we are migration legacy project to new packages and this time we are looking at contributte form renderers as replacement for instante/bootstrap3renderer. But at this point there are few things we would need to customize. We can make our own version but I think some of our changes could be useful for others so I have some suggestions. If you like it I can prepare PRs.

  1. Customizable label and control columns count. At this point if is hardcoded to 3:9 but in our project we often needs to customize it. I propose to add either public properties or setter to set column counts, replace hardcoded values in $wrappers with placeholders and replace placeholders by real values in DefaultFormRenderer::getValue.

  2. Current renderer always make first button without any class to btn-primary. It does not make much sense in most of our forms so we would have to explicitly add btn-* to all buttons. What about change it to make button primary only if it is only button in form? Or if no button in form has btn-* class?

  3. I do not know why some renderers do this? Is it really necessary?

$form->getElementPrototype()->setNovalidate(true);

Reneme namespace for renderers

@f3l1x what you are think about rename namespace for renderers?

From namespace Contributte\Forms\Renderers to Contributte\Forms\Rendering like in Nette/Forms?

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.