I have this weird problem at displaying Morris line chart.
It only displays data when I let the revenue-chart at the same page.
When I erase the block of revenue-chart, the line chart gets empty.
These are the codes before and after:
Functional:
<section class="content">
<div class="row">
<div class="col-md-6">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Area Chart</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body chart-responsive">
<div class="chart" id="revenue-chart" style="height: 300px;"></div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Line Chart</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body chart-responsive">
<div class="chart" id="line-chart" style="height: 300px;"></div>
</div>
</div>
</div>
</div>
</section>
Error:
<section class="content">
<div class="row">
<div class="col-md-6">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Line Chart</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body chart-responsive">
<div class="chart" id="line-chart" style="height: 300px;"></div>
</div>
</div>
</div>
</div>
</section>
I have found the problem.
But it was not logical.
I deleted the javascript code block for the revenue-chart:
// AREA CHART
var area = new Morris.Area({
element: 'revenue-chart',
resize: true,
data: [
{y: '2011 Q1', item1: 2666, item2: 2666},
{y: '2011 Q2', item1: 2778, item2: 2294},
{y: '2011 Q3', item1: 4912, item2: 1969},
{y: '2011 Q4', item1: 3767, item2: 3597},
{y: '2012 Q1', item1: 6810, item2: 1914},
{y: '2012 Q2', item1: 5670, item2: 4293},
{y: '2012 Q3', item1: 4820, item2: 3795},
{y: '2012 Q4', item1: 15073, item2: 5967},
{y: '2013 Q1', item1: 10687, item2: 4460},
{y: '2013 Q2', item1: 8432, item2: 5713}
],
xkey: 'y',
ykeys: ['item1', 'item2'],
labels: ['Item 1', 'Item 2'],
lineColors: ['#a0d0e0', '#3c8dbc'],
hideHover: 'auto'
});
At some way it was conflicting with the line-chart.
// LINE CHART
var line = new Morris.Line({
element: 'line-chart',
resize: true,
data: [
{y: '2011 Q1', item1: 2666},
{y: '2011 Q2', item1: 2778},
{y: '2011 Q3', item1: 4912},
{y: '2011 Q4', item1: 3767},
{y: '2012 Q1', item1: 6810},
{y: '2012 Q2', item1: 5670},
{y: '2012 Q3', item1: 4820},
{y: '2012 Q4', item1: 15073},
{y: '2013 Q1', item1: 10687},
{y: '2013 Q2', item1: 8432}
],
xkey: 'y',
ykeys: ['item1'],
labels: ['Item 1'],
lineColors: ['#3c8dbc'],
hideHover: 'auto'
});
Related
I'm trying to run #headlessui/vue package in Nuxt3 project.
I'm able to see the package in node_modules folder.
But I keep getting below error
Internal server error: Failed to resolve import "#headlessui/vue" from "components/LeftSideFilter.vue". Does the file exist?
LeftSideFilter.vue file code
<!--
This example requires Tailwind CSS v2.0+
This example requires some changes to your config:
```
// tailwind.config.js
module.exports = {
// ...
plugins: [
// ...
require('#tailwindcss/forms'),
],
}
```
-->
<template>
<div class="bg-white">
<div>
<!-- Mobile filter dialog -->
<TransitionRoot as="template" :show="mobileFiltersOpen">
<Dialog
as="div"
class="fixed inset-0 flex z-40 lg:hidden"
#close="mobileFiltersOpen = false"
>
<TransitionChild
as="template"
enter="transition-opacity ease-linear duration-300"
enter-from="opacity-0"
enter-to="opacity-100"
leave="transition-opacity ease-linear duration-300"
leave-from="opacity-100"
leave-to="opacity-0"
>
<DialogOverlay class="fixed inset-0 bg-black bg-opacity-25" />
</TransitionChild>
<TransitionChild
as="template"
enter="transition ease-in-out duration-300 transform"
enter-from="translate-x-full"
enter-to="translate-x-0"
leave="transition ease-in-out duration-300 transform"
leave-from="translate-x-0"
leave-to="translate-x-full"
>
<div
class="ml-auto relative max-w-xs w-full h-full bg-white shadow-xl py-4 pb-12 flex flex-col overflow-y-auto"
>
<div class="px-4 flex items-center justify-between">
<h2 class="text-lg font-medium text-gray-900">Filters</h2>
<button
type="button"
class="-mr-2 w-10 h-10 bg-white p-2 rounded-md flex items-center justify-center text-gray-400"
#click="mobileFiltersOpen = false"
>
<span class="sr-only">Close menu</span>
<XIcon class="h-6 w-6" aria-hidden="true" />
</button>
</div>
<!-- Filters -->
<form class="mt-4 border-t border-gray-200">
<h3 class="sr-only">Categories</h3>
<ul role="list" class="font-medium text-gray-900 px-2 py-3">
<li v-for="category in subCategories" :key="category.name">
<a :href="category.href" class="block px-2 py-3">
{{ category.name }}
</a>
</li>
</ul>
<Disclosure
as="div"
v-for="section in filters"
:key="section.id"
class="border-t border-gray-200 px-4 py-6"
v-slot="{ open }"
>
<h3 class="-mx-2 -my-3 flow-root">
<DisclosureButton
class="px-2 py-3 bg-white w-full flex items-center justify-between text-gray-400 hover:text-gray-500"
>
<span class="font-medium text-gray-900">
{{ section.name }}
</span>
<span class="ml-6 flex items-center">
<PlusSmIcon
v-if="!open"
class="h-5 w-5"
aria-hidden="true"
/>
<MinusSmIcon
v-else
class="h-5 w-5"
aria-hidden="true"
/>
</span>
</DisclosureButton>
</h3>
<DisclosurePanel class="pt-6">
<div class="space-y-6">
<div
v-for="(option, optionIdx) in section.options"
:key="option.value"
class="flex items-center"
>
<input
:id="`filter-mobile-${section.id}-${optionIdx}`"
:name="`${section.id}[]`"
:value="option.value"
type="checkbox"
:checked="option.checked"
class="h-4 w-4 border-gray-300 rounded text-indigo-600 focus:ring-indigo-500"
/>
<label
:for="`filter-mobile-${section.id}-${optionIdx}`"
class="ml-3 min-w-0 flex-1 text-gray-500"
>
{{ option.label }}
</label>
</div>
</div>
</DisclosurePanel>
</Disclosure>
</form>
</div>
</TransitionChild>
</Dialog>
</TransitionRoot>
<main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div
class="relative z-10 flex items-baseline justify-between pt-24 pb-6 border-b border-gray-200"
>
<h1 class="text-4xl font-extrabold tracking-tight text-gray-900">
New Arrivals
</h1>
<div class="flex items-center">
<Menu as="div" class="relative inline-block text-left">
<div>
<MenuButton
class="group inline-flex justify-center text-sm font-medium text-gray-700 hover:text-gray-900"
>
Sort
<ChevronDownIcon
class="flex-shrink-0 -mr-1 ml-1 h-5 w-5 text-gray-400 group-hover:text-gray-500"
aria-hidden="true"
/>
</MenuButton>
</div>
<transition
enter-active-class="transition ease-out duration-100"
enter-from-class="transform opacity-0 scale-95"
enter-to-class="transform opacity-100 scale-100"
leave-active-class="transition ease-in duration-75"
leave-from-class="transform opacity-100 scale-100"
leave-to-class="transform opacity-0 scale-95"
>
<MenuItems
class="origin-top-right absolute right-0 mt-2 w-40 rounded-md shadow-2xl bg-white ring-1 ring-black ring-opacity-5 focus:outline-none"
>
<div class="py-1">
<MenuItem
v-for="option in sortOptions"
:key="option.name"
v-slot="{ active }"
>
<a
:href="option.href"
:class="[
option.current
? 'font-medium text-gray-900'
: 'text-gray-500',
active ? 'bg-gray-100' : '',
'block px-4 py-2 text-sm',
]"
>
{{ option.name }}
</a>
</MenuItem>
</div>
</MenuItems>
</transition>
</Menu>
<button
type="button"
class="p-2 -m-2 ml-5 sm:ml-7 text-gray-400 hover:text-gray-500"
>
<span class="sr-only">View grid</span>
<ViewGridIcon class="w-5 h-5" aria-hidden="true" />
</button>
<button
type="button"
class="p-2 -m-2 ml-4 sm:ml-6 text-gray-400 hover:text-gray-500 lg:hidden"
#click="mobileFiltersOpen = true"
>
<span class="sr-only">Filters</span>
<FilterIcon class="w-5 h-5" aria-hidden="true" />
</button>
</div>
</div>
<section aria-labelledby="products-heading" class="pt-6 pb-24">
<h2 id="products-heading" class="sr-only">Products</h2>
<div class="grid grid-cols-1 lg:grid-cols-4 gap-x-8 gap-y-10">
<!-- Filters -->
<form class="hidden lg:block">
<h3 class="sr-only">Categories</h3>
<ul
role="list"
class="text-sm font-medium text-gray-900 space-y-4 pb-6 border-b border-gray-200"
>
<li v-for="category in subCategories" :key="category.name">
<a :href="category.href">
{{ category.name }}
</a>
</li>
</ul>
<Disclosure
as="div"
v-for="section in filters"
:key="section.id"
class="border-b border-gray-200 py-6"
v-slot="{ open }"
>
<h3 class="-my-3 flow-root">
<DisclosureButton
class="py-3 bg-white w-full flex items-center justify-between text-sm text-gray-400 hover:text-gray-500"
>
<span class="font-medium text-gray-900">
{{ section.name }}
</span>
<span class="ml-6 flex items-center">
<PlusSmIcon
v-if="!open"
class="h-5 w-5"
aria-hidden="true"
/>
<MinusSmIcon v-else class="h-5 w-5" aria-hidden="true" />
</span>
</DisclosureButton>
</h3>
<DisclosurePanel class="pt-6">
<div class="space-y-4">
<div
v-for="(option, optionIdx) in section.options"
:key="option.value"
class="flex items-center"
>
<input
:id="`filter-${section.id}-${optionIdx}`"
:name="`${section.id}[]`"
:value="option.value"
type="checkbox"
:checked="option.checked"
class="h-4 w-4 border-gray-300 rounded text-indigo-600 focus:ring-indigo-500"
/>
<label
:for="`filter-${section.id}-${optionIdx}`"
class="ml-3 text-sm text-gray-600"
>
{{ option.label }}
</label>
</div>
</div>
</DisclosurePanel>
</Disclosure>
</form>
<!-- Product grid -->
<div class="lg:col-span-3">
<RightSide />
<RightSide /> <RightSide /> <RightSide />
</div>
</div>
</section>
</main>
</div>
</div>
</template>
<script>
import RightSide from "./RightSide.vue";
import { ref } from "vue";
import {
Dialog,
DialogOverlay,
Disclosure,
DisclosureButton,
DisclosurePanel,
Menu,
MenuButton,
MenuItem,
MenuItems,
TransitionChild,
TransitionRoot,
} from "#headlessui/vue";
import { XIcon } from "#heroicons/vue/outline";
import {
ChevronDownIcon,
FilterIcon,
MinusSmIcon,
PlusSmIcon,
ViewGridIcon,
} from "#heroicons/vue/solid";
const sortOptions = [
{ name: "Most Popular", href: "#", current: true },
{ name: "Best Rating", href: "#", current: false },
{ name: "Newest", href: "#", current: false },
{ name: "Price: Low to High", href: "#", current: false },
{ name: "Price: High to Low", href: "#", current: false },
];
const subCategories = [
{ name: "Totes", href: "#" },
{ name: "Backpacks", href: "#" },
{ name: "Travel Bags", href: "#" },
{ name: "Hip Bags", href: "#" },
{ name: "Laptop Sleeves", href: "#" },
];
const filters = [
{
id: "color",
name: "Color",
options: [
{ value: "white", label: "White", checked: false },
{ value: "beige", label: "Beige", checked: false },
{ value: "blue", label: "Blue", checked: true },
{ value: "brown", label: "Brown", checked: false },
{ value: "green", label: "Green", checked: false },
{ value: "purple", label: "Purple", checked: false },
],
},
{
id: "category",
name: "Category",
options: [
{ value: "new-arrivals", label: "New Arrivals", checked: false },
{ value: "sale", label: "Sale", checked: false },
{ value: "travel", label: "Travel", checked: true },
{ value: "organization", label: "Organization", checked: false },
{ value: "accessories", label: "Accessories", checked: false },
],
},
{
id: "size",
name: "Size",
options: [
{ value: "2l", label: "2L", checked: false },
{ value: "6l", label: "6L", checked: false },
{ value: "12l", label: "12L", checked: false },
{ value: "18l", label: "18L", checked: false },
{ value: "20l", label: "20L", checked: false },
{ value: "40l", label: "40L", checked: true },
],
},
];
export default {
components: {
Dialog,
DialogOverlay,
Disclosure,
DisclosureButton,
DisclosurePanel,
Menu,
MenuButton,
MenuItem,
MenuItems,
TransitionChild,
TransitionRoot,
ChevronDownIcon,
FilterIcon,
MinusSmIcon,
PlusSmIcon,
ViewGridIcon,
XIcon,
RightSide,
},
setup() {
const mobileFiltersOpen = ref(false);
return {
sortOptions,
subCategories,
filters,
mobileFiltersOpen,
};
},
};
</script>
there was a point where I got stuck while trying to make invoice transactions with vue js, I can add a new item, it works fine, the problem starts here, when I want to show the "description" and "discount_value" that I have hidden, it adds it to all lines, not like this, whichever index button is clicked. add his item. Thank you in advance for your help.
const app = new Vue({
el: '#app',
data: {
addAciklama: false,
addIndirim: false,
faturasections: [
{
name: "",
unit_price: 0,
net_total: 0,
description: '',
discount_value: '',
}
],
},
methods: {
addNewFaturaSatiri() {
this.faturasections.push({
name: "",
unit_price: 0,
net_total: 0,
description: '',
discount_value: '',
});
},
removeFaturaSatiri(faturasectionIndex) {
this.faturasections.splice(faturasectionIndex, 1);
},
}
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.js"></script>
<div id="app">
<section>
<div class="card-body border-bottom-light" v-for="(fatura, faturasectionIndex) in faturasections" :key="faturasectionIndex">
<div class="row">
<div class="col-sm-4 col-12 mb-1 mb-sm-0 hizmet">
<div class="form-floating">
<input type="text" class="form-control" v-model="fatura.name" placeholder=" "/>
<label>HİZMET / ÜRÜN</label>
</div>
</div>
<div class="col-sm-2 col-12 mb-1 mb-sm-0 brfiyati">
<div class="form-floating">
<input type="number" class="form-control" v-model.number="fatura.unit_price" placeholder=" "/>
<label>BR.FİYAT</label>
</div>
</div>
<div class="col-sm-1 col-12 mb-1 mb-sm-0 toplam">
<div class="form-floating">
<input type="text" class="form-control" v-model="fatura.net_total" placeholder=" "/>
<label>TOPLAM</label>
</div>
</div>
<div class="col-sm-1 col-12 mb-1 mb-sm-0">
<div class="mb-1">
<div class="mb-1">
<button v-if="!addAciklama" #click="addAciklama = !addAciklama" class="dropdown-item">description</button>
<button v-if="!addIndirim" #click="addIndirim = !addIndirim" class="dropdown-item">discount_value</button>
</div>
</div>
<button class="btn btn-icon btn-secondary" #click="removeFaturaSatiri(faturasectionIndex)">DELETE</button>
</div>
</div>
<div id="aciklamalar" class="row mt-1">
<div class="col-12 d-flex">
<div class="col-sm-6 fatura-aciklama">
<div class="row" v-if="addAciklama">
<div class="f-a">
<div class="input-group">
<span class="input-group-text kdv">AÇIKLAMA</span>
<input type="text" class="form-control" v-model="fatura.description"/>
</div>
</div>
<div class="f-b">
<button class="btn btn-icon btn-outline-secondary" #click="addAciklama = !addAciklama">DELETE</button>
</div>
</div>
</div>
<div class="col-sm-5">
<div class="d-flex flex-column">
<div class="row row mb-1" v-if="addIndirim">
<div class="i-i">
<div class="input-group">
<span class="input-group-text kdv">İNDİRİM</span>
<input type="text" class="form-control" v-model="fatura.discount_value"/>
</div>
</div>
<div class="i-s">
<button class="btn btn-icon btn-outline-secondary" #click="addIndirim = !addIndirim">DELETE</button>
</div>
</div>
</div>
</div>
</div>
</div>
<hr>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-2">
<button type="button" class="btn btn-outline-secondary btn-sm"
data-repeater-create #click="addNewFaturaSatiri()">
<span class="align-middle">NEW INVOICE</span>
</button>
</div>
</div>
</div>
</section>
</div>
addAciklama and addIndirim are global variable which is defined in data property and it's obvious that if you change them, it applies to every iteration of your v-for block and not apply for each index separately.
In order to fix this, you can move addAciklama and addIndirim into each object in faturasections:
faturasections: [{
name: "",
unit_price: 0,
net_total: 0,
description: '',
discount_value: '',
addIndirim: false,
addAciklama: false,
}],
Then in your template section code, you should replace all addIndirim and addAciklama to fatura.addIndirim and fatura.addAciklama. this will fix your issue.
I tried to make the element 'branch' responsive aligned perfectly below 'status' when I tried to minimize the browser's window, how can I do that? This is what I've got so far result, I've also tried to use #media only screen CSS but still shows no sign of responsiveness, here's my lines of code
`
<template>
<base-header class="pb-4 pb-5 pt-6 pt-md-6 bg-gradient-success">
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1"
/>
<template>
<div>
<b-form inline>
<label for="status">Status⠀⠀⠀⠀ :</label>
<div class="col-sm-2">
<b-form-input v-model="text"></b-form-input>
</div>
<!-- branchstyle -->
<div class="branch">
<div class="col-lg-10 text-right">
<b-form inline label-align-sm="right" style="margin-left: 70px">
<div class="col-sm-2" label for="branch">Branch⠀:</div>
<div class="col-sm-8">
<b-form-input
v-model="text"
style="margin-left: 33px"
></b-form-input>
</div>
<br />
<!-- <div class="input-group col-sm-2">
<b-button variant="outline-dark"></b-button>
</div> -->
<!-- <div>
</div> -->
</b-form>
</div>
</div>
</b-form>
</div>
<div>
<b-form inline>
<label for="storecode">Store Code⠀:</label>
<div class="col-sm-2">
<b-form-input v-model="text"></b-form-input>
</div>
<div class="branch">
<div class="col-lg-12 text-right">
<b-form inline label-align-sm="right">
<div class="input-group col-sm-10">
<b-button
variant="dark"
style="margin-left: 205px; margin-top: 5px"
>Search</b-button
>
</div>
<!-- <div>
</div> -->
</b-form>
</div>
</div>
</b-form>
</div>
<br />
<br />
<b-card body>
<b-card-header class="border-0">
<h3 class="mb-0">Stock List</h3>
</b-card-header>
<div class="text-center">
<b-table dark striped hover :items="items" :fields="fields"></b-table
><br />
</div>
</b-card>
</template>
</base-header>
</template>
<style></style>`
Thanks in advance and hope u have a nice day☺
I try to simulate your issue and implement this code snippet. Because I couldn't see your result in the code snippet, I assume that you want a responsive form that, when the screen minimizes, your inputs are placed into the right section.
I've done some cleaning and improvements for better readability, and I used flex for your responsive issue.
new Vue({
el: "#app",
data: function() {
return {
text: "a",
fields: ['first_name', 'last_name', 'age'],
items: [{
isActive: true,
age: 40,
first_name: 'Dickerson',
last_name: 'Macdonald'
},
{
isActive: false,
age: 21,
first_name: 'Larsen',
last_name: 'Shaw'
},
{
isActive: false,
age: 89,
first_name: 'Geneva',
last_name: 'Wilson'
},
{
isActive: true,
age: 38,
first_name: 'Jami',
last_name: 'Carney'
}
]
}
},
});
.customForm>div {
display: flex;
flex: 1 0 250px;
margin: 1rem;
}
.customForm {
display: flex;
flex-wrap: wrap;
}
.customForm > div > label {
flex: 1 0 auto;
align-items: flex-end;
display: flex;
margin-right: .5rem;
}
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap-vue#latest/dist/bootstrap-vue.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue#latest/dist/bootstrap-vue.js"></script>
<div id="app">
<b-form class="customForm">
<div>
<label>Status:</label>
<b-form-input v-model="text" />
</div>
<div>
<label>Branch:</label>
<b-form-input v-model="text" />
</div>
<div>
<label>Store Code:</label>
<b-form-input v-model="text" />
</div>
<div>
<b-button variant="dark">Search</b-button>
</div>
</b-form>
<b-card body>
<b-card-header class="border-0">
<h3 class="mb-0">Stock List</h3>
</b-card-header>
<div class="text-center">
<b-table dark striped hover :items="items" :fields="fields" />
</div>
</b-card>
</div>
I want to show the schedule, with if condition. If the index in the loop is the same as the index day, then display 'index' else is '-'.
for now, this is my view:
My code:
<td v-for="(n, i) in 7" :key="i">
<span :key="index" v-for="(item, index) in item.schedule_detail">
<span v-if="item.day === i">
<span>{{ item.day }}</span>
</span>
<span v-else>-</span>
</span>
</td>
My expectations:
Thanks a lot.
This v-if logic should work fine. See the below code
new Vue({
el: '#app',
data: {
item: {
schedule_detail: [{
"id": 1,
"doctor_schedule_id": 1,
"day": 0,
"from_time": "08:00:00",
"until_time": "12:00:00",
"from_time_2": "17:00:00",
"until_time_2": "21:00:00",
},
{
"id": 2,
"doctor_schedule_id": 1,
"day": 2,
"from_time": "08:00:00",
"until_time": "21:00:00",
"from_time_2": null,
"until_time_2": null,
}
]
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id='app'>
<td><span :key="index" v-for="(i, index) in 7">
<span v-if= "(i=item.schedule_detail.findIndex(x=>x.day===index)) >=0 ">
{{item.schedule_detail[i].day}}
</span>
<span v-else>-</span>
</span>
</td>
</div>
I am beginner in dojo, i have done some work but unable to add the form value into respective cell in the grid, After click on the submit button.
Here my Dojo script
require([
"dojo/_base/lang",
"dojo/dom",
"dojo/dom-construct",
"dojo/on",
"dojo/dom-form",
"dijit/form/TextBox",
"dijit/form/Button",
"dojox/grid/DataGrid",
"dojo/store/Memory",
"dojo/data/ObjectStore",
"dojo/request",
"dojo/domReady!"
],
function(lang, dom, domConstruct, on, domForm, TextBox, Button, DataGrid, Memory, ObjectStore, request)
{
var formJson, first, last, dob, city, state, country, mobile, formId, dataStore, grid;
/*set up layout*/
var layout = [[
{'name': 'First name', 'field': 'id', 'width': '100px'},
{'name': 'Last Name', 'field': 'col2', 'width': '100px'},
{'name': 'DOB', 'field': 'col3', 'width': '200px'},
{'name': 'City', 'field': 'col4', 'width': '150px'},
{'name': 'State', 'field': 'col5', 'width': '150px'},
{'name': 'Country', 'field': 'col6', 'width': '150px'},
{'name': 'Mobile', 'field': 'col7', 'width': '150px'},
]];
/*create a new grid*/
var grid = new DataGrid(
{
store: dataStore,
query: { id: "*" },
queryOptions: {},
structure: layout
}, "grid");
/*append the new grid to the div*/
grid.placeAt("gridDiv");
/*Call startup() to render the grid*/
grid.startup();
});
function submitForm() {
first= dijit.byId('first').get('value');
last= dijit.byId('last').get('value');
dob= dijit.byId('dob').get('value');
city= dijit.byId('city').get('value');
state= dijit.byId('state').get('value');
country= dijit.byId('country').get('value');
mobile= dijit.byId('mobile').get('value');
//console.log(first+','+last+','+dob+','+city+','+state+','+country+','+mobile);
formId = "myform";
formJson = domForm.toJson(formId);
console.log(formJson);
//dataStore.add(formJson);
//grid.setQuery({id: "*"});
}
// Connect the buttons
on(dom.byId("submitForm"), "click", submitForm);
console.log(formJson);
});
and html
<body class="claro">
<div id="wrapper">
<form id="myform">
<div id="formContainer">
<div class="row">
<label>First Name</label>
<input type="text" id="first" name="first" data-dojo-type="dijit.form.TextBox" value="Thilakar" />
</div>
<div class="row">
<label>Last Name</label>
<input type="text" id="last" name="last" data-dojo-type="dijit.form.TextBox" value="Kathirvel" />
</div>
<div class="row">
<label>DOB</label>
<input type="text" id="dob" name="dob" data-dojo-type="dijit.form.TextBox" value="07/10/1983"/>
</div>
<div class="row">
<label>City</label>
<input type="text" id="city" name="city" data-dojo-type="dijit.form.TextBox" value="Chennai"/>
</div>
<div class="row">
<label>State</label>
<input type="text" id="state" name="state" data-dojo-type="dijit.form.TextBox" value="Tamilnadu"/>
</div>
<div class="row">
<label>Country</label>
<input type="text" id="country" name="country" data-dojo-type="dijit.form.TextBox" value="India"/>
</div>
<div class="row">
<label>Mobile</label>
<input type="text" id="mobile" name="mobile" data-dojo-type="dijit.form.TextBox" value="9094730388"/>
</div>
<div class="row">
<label> </label>
<input type="button" value="submit" id="submitForm"/>
</div>
</div>
</form>
<h1>Saved Data</h1>
<div id="gridDiv"></div>
</div>
</body>
please give some suggestion how it's possible.
Thanks
There are several issues. See working example here : http://jsfiddle.net/psoares/Hm8j2/
I changed your html to this :
<div id="wrapper">
<form id="myform">
<div id="formContainer">
<div class="row">
<label>First Name</label>
<input type="text" id="first" name="first" data-dojo-type="dijit/form/TextBox" value="Thilakar" />
</div>
<div class="row">
<label>Last Name</label>
<input type="text" id="last" name="last" data-dojo-type="dijit/form/TextBox" value="Kathirvel" />
</div>
<div class="row">
<label>DOB</label>
<input type="text" id="dob" name="dob" data-dojo-type="dijit/form/TextBox" value="07/10/1983"/>
</div>
<div class="row">
<label>City</label>
<input type="text" id="city" name="city" data-dojo-type="dijit/form/TextBox" value="Chennai"/>
</div>
<div class="row">
<label>State</label>
<input type="text" id="state" name="state" data-dojo-type="dijit/form/TextBox" value="Tamilnadu"/>
</div>
<div class="row">
<label>Country</label>
<input type="text" id="country" name="country" data-dojo-type="dijit.form.TextBox" value="India"/>
</div>
<div class="row">
<label>Mobile</label>
<input type="text" id="mobile" name="mobile" data-dojo-type="dijit/form/TextBox" value="9094730388"/>
</div>
<div class="row">
<label> </label>
<button type="submit" value="submit" data-dojo-type="dijit/form/Button" id="submitForm">Submit</button>
</div>
</div>
</form>
<h1>Saved Data</h1>
<div id="gridDiv"></div>
And your javascript to :
require([
"dojo/_base/lang",
"dojo/dom",
"dojo/dom-construct",
"dojo/on",
"dijit/form/Form",
"dijit/form/TextBox",
"dijit/form/Button",
"dojox/grid/DataGrid",
"dojo/store/Memory",
"dojo/data/ObjectStore",
"dojo/request",
"dijit/registry",
"dojo/domReady!"
], function(lang, dom, domConstruct, on, Form, TextBox, Button, DataGrid, Memory, ObjectStore, request, registry){
var layout, dataStore, grid, form;
/*set up layout*/
layout = [
{'name': 'First name', 'field': 'first', 'width': '100px'},
{'name': 'Last Name', 'field': 'last', 'width': '100px'},
{'name': 'DOB', 'field': 'dob', 'width': '200px'},
{'name': 'City', 'field': 'city', 'width': '150px'},
{'name': 'State', 'field': 'state', 'width': '150px'},
{'name': 'Country', 'field': 'country', 'width': '150px'},
{'name': 'Mobile', 'field': 'mobile', 'width': '150px'}
];
dataStore = new ObjectStore({ objectStore : new Memory() });
/*create a new grid*/
grid = new DataGrid({
store: dataStore,
query: { id: "*" },
queryOptions: {},
structure: layout
}, "gridDiv");
/*Call startup() to render the grid*/
grid.startup();
form = new Form({
onSubmit : function(evt) {
evt.preventDefault();
var formValue = this.get("value");
console.debug(formValue);
dataStore.newItem(formValue);
}
}, "formContainer");
form.startup();
});