2020-12-08 19:23

Client-side validation checks irrelevant form fields

I have a grid with adding and editing, and some values are mandatory. When I try to edit a row, netteForms.js validation won't let me to submit the form, because there is that hidden inline add form with invalid data.

You can try it with this simple example:

     *  DataGrid
    protected function createComponentTestGrid()
        $grid = new DataGrid;
            ['id' => 1, 'foo' => 'bar'],
            ['id' => 2, 'foo' => 'baz'],
        $grid->addColumnText('foo', 'Foo');
        $editor = $grid->addInlineEdit();
        $creator = $grid->addInlineAdd();
        $editor->onControlAdd[] =
        $creator->onControlAdd[] = function (Container $container) {
        $editor->onSetDefaults[] = function (Container $container, $item) {
                'foo' => $item['foo'],

        return $grid;

The same issue may occur, when you have several rows open for editing and one of them contains an invalid value.

Any thoughts how to solve this?

Approaches that I though about: - Disable all irrelevant form fields, then re-enable them again. Nope, it would cause more problems than it solves. - Use $.nette.ajax() directly. But then the client-side validation wouldn't run at all. - On submit, create a new hidden form element, copy relevant fields into this form and submit it.


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39628063 weixin_39628063 5月前

    These form validations are a bit overkill for inline add in my opinion. I have to think about it more complex way.

    点赞 评论 复制链接分享
  • weixin_39932762 weixin_39932762 5月前

    I've noticed that you don't create Form (filter) submit button, precisely it's created automatically, we are unable to add the validation scope for filtering. I've managed to overcome this in editing via $container['submit'] provided in callback, is there any possibility to similarly deal with the problem?

    点赞 评论 复制链接分享
  • weixin_39928736 weixin_39928736 5月前

    I have run into similiar issue with group actions. It was not possible to execute group action combined with inline add and Nette rules.

    Although I don't like it, I had to do something like this:

    $grid['filter']['group_action']['submit']->setValidationScope([ $grid['filter']['group_action'] ]);

    Maybe all submit buttons should have their validation scopes set to their respective containers?

    点赞 评论 复制链接分享
  • weixin_39976951 weixin_39976951 5月前

    This has been fixed in #451.

    点赞 评论 复制链接分享