Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public function update($id, $data = null)
$this->updateRelation($this->relations);
});

if (($result = $this->callSaved()) instanceof Response) {
if (($result = $this->callUpdated()) instanceof Response) {
return $result;
}

Expand Down
26 changes: 24 additions & 2 deletions src/Form/Concerns/HasHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
trait HasHooks
{
/**
* Supported hooks: submitted, editing, saving, saved, deleting, deleted.
* Supported hooks: submitted, editing, saving, saved, updated, deleting, deleted.
*
* @var array
*/
Expand Down Expand Up @@ -134,6 +134,18 @@ public function saved(Closure $callback)
return $this->registerHook('saved', $callback);
}

/**
* Set updated callback.
*
* @param Closure $callback
*
* @return $this
*/
public function updated(Closure $callback)
{
return $this->registerHook('updated', $callback);
}

/**
* @param Closure $callback
*
Expand Down Expand Up @@ -185,7 +197,7 @@ protected function callSaving()
}

/**
* Callback after saving a Model.
* Callback after saving a Model (new model).
*
* @return mixed|null
*/
Expand All @@ -194,6 +206,16 @@ protected function callSaved()
return $this->callHooks('saved');
}

/**
* Callback after updating a Model.
*
* @return mixed|null
*/
protected function callUpdated()
{
return $this->callHooks('updated');
}

/**
* Call hooks when deleting.
*
Expand Down
14 changes: 9 additions & 5 deletions src/Form/EmbeddedForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,16 @@ public function setOriginal($data)
*/
public function prepare($input)
{
foreach ($input as $key => $record) {
$this->setFieldOriginalValue($key);
$input[$key] = $this->prepareValue($key, $record);
}
if (is_array($input)) {
foreach ($input as $key => $record) {
$this->setFieldOriginalValue($key);
$input[$key] = $this->prepareValue($key, $record);
}

return $input;
return $input;
} else {
return [];
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Form/Field/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function render()
$this->options['allowInputToggle'] = true;
$this->check_format_options();

$this->script = "flatpickr('{$this->getElementClassSelector()}',".json_encode($this->options).');';
$name= $this->elementName ?: $this->formatName($this->column);
$this->script = "flatpickr('input[name=\"{$name}\"]',".json_encode($this->options).');';

$this->prepend('<i class="icon-calendar fa-fw"></i>');
$this->style('max-width', '160px');
Expand Down
5 changes: 4 additions & 1 deletion src/Form/Field/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,10 @@ protected function setupScriptForDefaultView($templateScript)
index++;

var tpl = document.querySelector('template.{$this->column}-tpl').innerHTML;
var script = `{$templateScript}`;

tpl = tpl.replace(/{$defaultKey}/g, index);
script = script.replace(/{$defaultKey}/g, index);
var clone = htmlToElement(tpl);
addRemoveHasManyListener{$this->column}(clone.querySelector('.remove'));
document.querySelector('.has-many-{$this->column}-forms').appendChild(clone);
Expand All @@ -525,7 +528,7 @@ protected function setupScriptForDefaultView($templateScript)
addHasManyTab{$this->column}(index);
}

{$templateScript}
eval(script);
return false;

});
Expand Down
3 changes: 2 additions & 1 deletion src/Form/Field/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public function render()
empty($this->attributes['readonly']) &&
empty($this->attributes['disabled'])
) {
$name= $this->elementName ?: $this->formatName($this->column);
$this->script = <<<JS
new NumberInput(document.querySelector('{$this->getElementClassSelector()}'));
new NumberInput(document.querySelector('input[name=\"{$name}\"]'));
JS;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Form/Field/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ public function render()
$configs = json_encode($configs);

if (!$this->native && $this->allowedChoicesJs()) {
$this->script .= 'var '.$this->choicesObjName()." = new Choices('{$this->getElementClassSelector()}',{$configs});";
$name= $this->elementName ?: $this->formatName($this->column);
$this->script .= 'var '.$this->choicesObjName()." = new Choices('select[name=\"{$name}\"]',{$configs});";
$this->script .= $this->additional_script;
}

Expand Down