Skip to content

Commit

Permalink
fix json type
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Dillingham committed Feb 4, 2019
1 parent b89012b commit c3dab04
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 43 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

55 changes: 25 additions & 30 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@
<default-field :field="field" :full-width-content="field.fullWidth">
<template slot="field" class="nova-items-field">
<div class="nova-items-field-input-wrapper flex border border-40 p-4" v-if="field.listFirst == false && ! maxReached">
<input
<input
v-model="newItem"
:type="field.inputType"
:placeholder="field.placeholder"
class="flex-1 form-control form-input form-input-bordered"
/>
<a
@click="addItem"
<a
@click="addItem"
v-html="field.createButtonValue"
v-if="field.hideCreateButton == false"
class="btn btn-default btn-primary ml-3 cursor-pointer"
v-if="field.hideCreateButton == false"
class="btn btn-default btn-primary ml-3 cursor-pointer"
/>
</div>
<ul ref="novaitemslist" :style="maxHeight" v-if="items.length" class="nova-items-field-input-items list-reset border border-40 py-2">
<draggable v-model="items" :options="{ disabled: field.draggable == false, handle: '.sortable-handle' }">
<li
v-for="(item, index) in items"
:key="field.attribute + '.' + index"
<li
v-for="(item, index) in items"
:key="field.attribute + '.' + index"
class="px-4 py-2"
>

<div class="nova-items-field-input-wrapper-item flex py-1">
<span v-if="field.draggable" class="sortable-handle py-2 pl-0 pr-4 text-80 cursor-move">
|||
</span>
<input
:value="item"
<input
:value="item"
:type="field.inputType"
v-on:keyup="updateItem(index, $event)"
:name="field.name + '['+ index +']'"
:name="field.name + '['+ index +']'"
:class="{'border-danger': hasErrors(field.attribute + '.' + index)}"
class="flex-1 form-control form-input form-input-bordered"
>
<span
@click="removeItem(index)"
<span
@click="removeItem(index)"
class="ml-4 mr-2 font-thin text-2xl cursor-pointer hover:font-normal"
v-html="field.deleteButtonValue"
/>
Expand All @@ -55,11 +55,11 @@
class="flex-1 form-control form-input form-input-bordered"
@keypress.enter.prevent="addItem"
/>
<a
@click="addItem"
<a
@click="addItem"
v-html="field.createButtonValue"
v-if="field.hideCreateButton == false"
class="btn btn-default btn-primary ml-3 cursor-pointer"
v-if="field.hideCreateButton == false"
class="btn btn-default btn-primary ml-3 cursor-pointer"
/>
</div>
</template>
Expand All @@ -77,7 +77,7 @@
-o-user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
user-select: none;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
Expand Down Expand Up @@ -111,29 +111,24 @@ export default {
methods: {
setInitialValue() {
setInitialValue() {
this.value = this.field.value || '';
this.$nextTick(() => {
this.items = (this.value)
? JSON.parse(this.value)
: [];
});
this.items = this.field.value;
},
fill(formData) {
formData.append(this.field.attribute, this.value || '')
},
addItem() {
const item = this.newItem.trim()
if (item && ! this.maxReached) {
this.items.push(item)
this.newItem = ''
this.$nextTick(() => {
if(this.field.maxHeight){
this.$refs.novaitemslist.scrollTop = this.$refs.novaitemslist.scrollHeight;
Expand All @@ -150,7 +145,7 @@ export default {
removeItem (index) {
this.items.splice(index, 1)
},
hasErrors(key)
{
return this.arrayErrors.hasOwnProperty(key);
Expand Down
28 changes: 16 additions & 12 deletions src/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function resolve($resource, $attribute = null)
{
parent::resolve($resource, $attribute);

$this->fillUsing(function($request, $model, $attribute, $requestAttribute) {
$model->$attribute = json_decode($request->$attribute, true);
});

$this->withMeta([
'max' => $this->max,
'items' => $this->items,
Expand All @@ -45,46 +49,46 @@ public function rules($rules)
if (!is_array($rules)) {
abort(500, 'Nova Items Field requires array of validation rules');
}

$this->rules = [ new ArrayRules($rules) ];

return $this;
}

public function values($values)
{
if (is_array($values) && count($values)) {
$this->items = $values;
}

return $this;
}

public function max($max)
{
$this->max = $max;

return $this;
}

public function hideCreateButton($hideCreateButton = true)
{
$this->hideCreateButton = $hideCreateButton;

return $this;
}

public function inputType($inputType)
{
$this->inputType = $inputType;

return $this;
}

public function fullWidth($fullWidth = true)
{
$this->fullWidth = $fullWidth;

return $this;
}

Expand All @@ -98,35 +102,35 @@ public function maxHeight($maxHeight)
public function draggable($draggable = true)
{
$this->draggable = $draggable;

return $this;
}

public function placeholder($placeholder)
{
$this->placeholder = $placeholder;

return $this;
}

public function listFirst($listFirst = true)
{
$this->listFirst = $listFirst;

return $this;
}

public function deleteButtonValue($deleteButtonValue)
{
$this->deleteButtonValue = $deleteButtonValue;

return $this;
}

public function createButtonValue($createButtonValue)
{
$this->createButtonValue = $createButtonValue;

return $this;
}

Expand Down

0 comments on commit c3dab04

Please sign in to comment.