This Blade implements a view form that is extended by Vue 1.0 Beta 4. The form cannot post unless BOTH long name and short name are filled.
@extends('coverage::layouts.coverage_category')
@section('cat-content')
<div id="app-container">
<h2>Coverage Categories</h2>
<form name="form1" action="">
<div id="select">
<select v-model="selected" v-on:change="onListSelect" id="list_box" size="10">
<option v-for="opt in selectOptions" v-bind:value="opt">@{{opt.text}}</option>
</select>
</div>
<div id="input-area">
<div id="short-name">
Short Name:
<input v-model="shortName" v-on:change="textChange" lazy
type="text" id="shortName" class="req" maxlength="8" size="10">
</div>
<div id="long-name">
Long Name:
<input v-model="longName" v-on:change="textChange" lazy
type="text" id="longName" class="req" size="32" maxlength="30">
</div>
<div id="btns">
<button v-on:click="execCommand" class="btn" id="save">Save</button>
<button v-on:click="execClear" class="btn" id="clear">Clear</button>
</div>
</div>
</form>
<p>Short name: <strong>@{{shortName}}</strong></p>
<p>Long name: <strong>@{{longName}}</strong></p>
<p>Selected: <strong>@{{selected.value}}</strong></p>
</div>
@stop
Here is the Vue model to control the Save/Update button.
app = new Vue({
el: '#app-container',
data: {
shortName: "",
longName: "",
selectOptions: [],
selected: -1,
},
methods: {
addOption: function (opt) {
this.selectOptions.push(opt);
},
onListSelect: function (e) {
fyi('selcted ' + this.selected.value);
find(this.selected.value);
},
clearList: function () {
this.selectOptions = [];
this.selected = -1;
},
setShortName: function (name) {
this.shortName = name;
},
setLongName: function (name) {
this.longName = name;
},
getShortName: function () {
return this.shortName;
},
getLongName: function () {
return this.longName;
},
setSelected: function (s) {
this.selected = this.selectOptions[s];
},
getSelected: function () {
if (this.selected != -1) {
return this.selected.value;
}
return -1;
},
execCommand: function (e) {
sqlBusy = true;
if (e != undefined) {
e.preventDefault();
}
var postData = {
id: this.getSelected(),
shortName: this.getShortName().toUpperCase(), // Each entry is a separate $_POST['id'] item on backend.
longName: this.getLongName().toUpperCase()
};
if (cmd == INSERT) {
url = 'create';
} else if (cmd == UPDATE) {
url = 'update';
}
payLoad
//.setOnRecover(this.execCommand)
.setOnPayload(null)
.call(url, postData);
},
textChange: function (e) {
//alert("on change...");
controlButtons();
},
execClear: function (e) {
if (e != undefined) {
e.preventDefault();
}
this.setShortName("");
this.setLongName("");
cmd = INSERT;
setCmdButton(cmd);
controlButtons();
clearSelection();
fieldShortName.focus();
}
}
});
btnClear.prop('disabled', true);
btnSave.prop('disabled', true);
//fyi("event setup...");
$('.req').bind('keyup', function(event) {
controlButtons();
});
}
External Methods...
function requiredFields() {
var count = 0;
if (fieldShortName.val().length > 0)
{
++ count;
fieldShortName.css("border", "1px solid #00FF00");
} else {
fieldShortName.css("border", " 1px solid #FF0100");
}
if (fieldLongName.val().length > 0)
{
++ count;
fieldLongName.css("border", "1px solid #00FF00");
} else {
fieldLongName.css("border", "1px solid #FF0100");
}
return count;
}
function setBorderColors() {
if (fieldShortName.val().length > 0)
{
fieldShortName.css("border", "1px solid #00FF00");
} else {
fieldShortName.css("border", " 1px solid #FF0100");
}
if (fieldLongName.val().length > 0)
{
fieldLongName.css("border", "1px solid #00FF00");
} else {
fieldLongName.css("border", "1px solid #FF0100");
}
}
function clearSelection() {
list.val("");
}
function controlButtons() {
switch (requiredFields()) {
case 1:
btnClear.prop('disabled', false);
btnSave.prop('disabled', true);
break;
case 2:
btnClear.prop('disabled', false);
btnSave.prop('disabled', false);
break;
default:
btnClear.prop('disabled', true);
btnSave.prop('disabled', true);
break;
}
}
function Option(t, v) {
this.text = t;
this.value = v;
};
// Lets snag some jQuery Selectors.
var cmdButton = $("#save");
var fieldShortName = $("#shortName");
var fieldLongName = $("#longName");
var btnClear = $('#clear');
var btnSave = $('#save');
var list = $("#list_box");
setCmdButton(INSERT);
// Set Network SQL flag to not busy.
var sqlBusy = false;
function msgPayload(p) {
fyiMsg(p);
index();
}
function errPayload(p) {
fyiErr(p);
}
var that = this;
// Setup Vue Model
var app = null;
function setCmdButton(_cmd) {
cmd = _cmd;
cmdButton.text(cmdText[cmd]);
}