Editor PHP events

Editor PHP events

ZakInterDevZakInterDev Posts: 51Questions: 16Answers: 0
edited October 2015 in Editor

Hi guys

So I'm using the new PHP events 'preCreate' etc that come with editor 1.5. I've used it as shown in the examples (https://editor.datatables.net/manual/php/events), and they work all fine. My problem lies when I'm doing additional validation on a field. The validator method doesn't seem to get called at all.

$ed = Editor::inst("omitted");
$code = Field::inst('code');
$ed->on('preCreate', function ($editor, $values) {
      $code->validator(function($val, $data, $opts)  {
            $count = $this->onCreateCodeValidation($data);
            return $count > 0 ? 'This code has already been used' : true;
      });
});
$ed->field($code);

Even if I hard code $count > 0 to 1 > 0. The error isn't thrown. So as this is a custom validation I tried adding a default one, using 'Validate::required' and that also doesn't get included.

Just wondering if this is a bug or perhaps there is a work around? I'd prefer to use these on() calls as they give the $id and $value parameters.

Thanks in advance!

edited

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin
    Answer ✓

    Hi,

    The issue here is that by the time the preCreate event is triggered the validation has already occurred. Therefore, you see what you are - the extra validation method does not get executed.

    Short of rearranging the code (which I will look at doing for 1.5.2 as I can see this would be useful), there unfortunately isn't a way of doing this at the moment with events.

    Allan

  • ZakInterDevZakInterDev Posts: 51Questions: 16Answers: 0

    I thought that might be the case.

    No worries, as long as it's noted down :) We're in the early stages of development for this current project, so if it could be done for 1.5.2 that would be great.

    Keep up the good work!

    Thanks

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    Quick update - I've just committed the change required for this feature and both the .NET and PHP libraries will provide this ability with Editor 1.5.2 (which shouldn't be too far away!).

    Regards,
    Allan

  • ZakInterDevZakInterDev Posts: 51Questions: 16Answers: 0

    Great news! We're coming to the point now where we're going to need it. Don't suppose I could get the inside scoop on its release? ;D

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin
    Answer ✓

    As in the date? Expecting it next week (assuming I can figure out the RequireJS stuff that is currently holding me up!).

    Allan

This discussion has been closed.