Hello,
I am trying to create and validate a form using DialogFormDocument. The form gets created during a method in a class inheriting AbstractDatabaseObjectAction. This method furthermore gets called by using the WoltLabSuite/Core/Form/Builder/Dialog.
JavaScript
var dialog = new FormBuilderDialog(
'testDialog',
'wcf\\data\\test\\MyDboAction',
'getDialog',
{
dialog: {
title: 'Dialog Title'
},
submitActionName: 'save'
}
);
dialog.open();
Alles anzeigen
PHP: TestObjectAction::getDialog()
$dialog = DialogFormDocument::create('testDialog');
$dialog->appendChildren([
IntegerFormField::create('userID')
->addValidator(new FormFieldValidator('duplicateUserID', function(IFormField $formField) {
if ($formField->getValue() == WCF::getUser()->userID) {
$formField->addValidationError(new FormFieldValidationError(
'duplicateUserID'
));
}
}))
->label('wcf.user.userID')
->required()
]);
$dialog->build();
return [
'dialog' => $dialog->getHtml(),
'formId' => $dialog->getId()
];
Alles anzeigen
My problem is that the FormFieldValidator never gets called and the input therefore never gets validated. The documentation does not state out any information about the validation process using DialogFormDocument.
I've tried to store the form in a class variable (and then call validate()) instead of a local one but as the class gets new instantiated during the submittment of the form the created PHP dialog is not available anymore.
PHP
class MyDboAction extends AbstractDatabaseObjectAction {
public $dialog;
public function getDialog() {
$this->dialog = DialogFormDocument::create('testDialog');
$this->dialog->appendChildren([
IntegerFormField::create('userID')
->addValidator(new FormFieldValidator('duplicateUserID', function(IFormField $formField) {
if ($formField->getValue() == WCF::getUser()->userID) {
$formField->addValidationError(new FormFieldValidationError(
'duplicateUserID'
));
}
}))
->label('wcf.user.userID')
->required()
]);
$this->dialog->build();
return [
'dialog' => $this->dialog->getHtml(),
'formId' => $this->dialog->getId()
];
}
public function save() {
$this->dialog->validate(); // Call to a member function validate() on null
}
public function validateGetDialog() {}
public function validateSave() {}
}
Alles anzeigen
So what's the correct way? What am I missing?