I try to delete the row but I can't I have already tested my model and my controller but with the element-ui table I can't, help please ?
im using Inertiajs with Ziggy route , laravel 9 and vue3
the error : Cannot read properties of undefined (reading 'id')
i try delete the row directly without model the same problem
the Script :
const props = defineProps({
clients: Array,
client: Object,
})
const confirmingClientDeletion = ref(false)
const form = useForm()
const confirmClientDeletion = () => {
confirmingClientDeletion.value = true
setTimeout(250)
}
const deleteClient = () => {
form.delete(route('clients.destroy', props.client.id), {
preserveScroll: true,
onSuccess: () => closeModal(),
onFinish: () => form.reset(),
})
}
const closeModal = () => {
confirmingClientDeletion.value = false
form.reset()
}
the template :
<div class="px-2">
<div class="md:container-2xl rounded-lg bg-white shadow-lg text-gray-700 text-l font-medium mb-4">
<div class="p-12 content-center">
<el-table :data="clients" style="width: 100%">
<el-table-column prop="id" label="id" width="180" />
<el-table-column prop="companyname" label="Raison Sociale" width="180" />
<el-table-column prop="town" label="Ville" width="120" />
<el-table-column prop="created_at" label="Date de creation" width="150" />
<el-table-column fixed="right" label="Operations" width="200">
<template #default>
<el-button size="small">Modifier</el-button>
<el-button size="small" type="danger" #click="confirmClientDeletion">Supprimer</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
</div>
<DialogModal :show="confirmingClientDeletion" #close="closeModal">
<template #title> Suppression des clients </template>
<template #content> Vous êtes sûr de vouloir supprimer définitivement le client? </template>
<template #footer>
<SecondaryButton #click="closeModal"> Annuler </SecondaryButton>
<DangerButton
class="ml-3"
:class="{ 'opacity-25': form.processing }"
:disabled="form.processing"
#click="deleteClient"
>
Supprimer client
</DangerButton>
</template>
</DialogModal>
Destroy function in The controller :
public function destroy(Client $client)
{
$client->delete();
return redirect()->route('clients.index');
}
Related
I'm creating an app in Laravel 9 using Vue 3. I have a list that I would like to filter, based on the selection of a dropdown. To ensure the continuity of the selection, I store the value in a ref (gamekk). My code is working to a point: gamekk is updated with the selected value, my computed list filters on the value of gamekk, and the list is displayed. It's only there momentarily, though. Immediately after, gamekk is reset and the list disappears. I can confirm this by displaying gamekk in my page - the value appears then disappears. I don't reference gamekk anywhere else (I added the 'kk' to be sure').
My script is:
<script setup>
import AuthenticatedLayout from '#/Layouts/AuthenticatedLayout.vue';
import { Head, Link, usePage } from '#inertiajs/inertia-vue3';
import PrimaryButton from '#/Components/PrimaryButton.vue';
import Dropdown from '#/Components/Dropdown.vue';
import DropdownLink from '#/Components/DropdownLink.vue';
import { Inertia } from '#inertiajs/inertia';
import {ref, reactive, computed} from 'vue';
const props = defineProps({
categories: {
type: Object,
default: () => ({}),
},
games: {
type: Object,
default: () => ({})
},
languages: {
type: Object,
default: () => ({})
}
});
const gamekk = ref();
const langFil = ref();
const cats = computed( () => {
return usePage().props.value.categories.filter(cat =>
(cat.game == gamekk.value)
);
});
function filterCats(filter, name) {
switch(filter) {
case 'game':
gamekk.value = name;
break;
case 'language':
langFil.value = name;
break;
}
}
</script>
I filter the list using:
<div class="flex">
Game
<div class="hidden sm:flex sm:items-center sm:ml-6">
<!-- Settings Dropdown -->
<div class="ml-3 relative">
<Dropdown align="right" width="48">
<template #trigger>
<span class="inline-flex rounded-md">
<button type="button" class="inline-flex items-center px-3 border border-transparent text-lg leading-4 font-medium rounded-md text-gray-700 hover:text-gray-500 focus:outline-none transition ease-in-out duration-150">
<svg class="ml-2 -mr-0.5 h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</button>
</span>
</template>
<template #content>
<DropdownLink v-for="game in $page.props.games" :key="game.id" #click="filterCats('game', game.name)">{{ game.name }}</DropdownLink>
</template>
</Dropdown>
</div>
</div>
</div>
I've used refs in this way before without problem. What am I missing that might reset the value automatically?
// I am trying to print out the database elements to react typescript home page, but when i print // it out it prints out
// [Object] [Object].
function HomePage(){
const [games, setGames] = useState< IGame []>([]);
useEffect(() => {
GameService.GetAllGames().then((data) => setGames(data));
}, []);
function onClickCreateADivWithGamesInfromation(){
const div = document.createElement('div');
const informationAboutGames = document.createElement('information');
informationAboutGames.innerText = `
${games.map((game, index) => {
return <GamesItem key={index} {...game} />
})}`;
JSON.stringify(informationAboutGames);
div.appendChild(informationAboutGames);
document.body.appendChild(div);
}
return(
<div>
<header>
<h1 className='text-center mb-5 '>Electric games</h1>
</header>
<br />
<main>
<div className='text-center'>
<h3 className='text-center'>Show all games</h3>
<button className='btn btn-primary' onClick={onClickCreateADivWithGamesInfromation} >Show all</button>
</div>
I have an AddressForm.vue where I have all the fields related to an address. I have imported it into a UserForm.vue and adding a user works fine.
Now I want to use the UserForm for editing a user, but I don't get the AddressForm fields pre-populated. The fields which are directly on the UserForm get pre-populated.
How can I get the AddressForm fields also pre-populated?
Here is my code:
AddressForm.vue:
<template>
<BaseCard>
<div class="card-header">{{ $t('address') }}</div>
<div class="card-body">
<BaseInput
v-model="street"
name="street_address"
label="street_address"
:value="street"
#input="$emit('update:street', $event.target.value)"
/>
<!-- <BaseInput
v-model="street"
name="street_address"
label="street_address"
:value="address.street"
#input="$emit('update:street', $event.target.value)"
/> -->
<BaseInput
v-model="street2"
name="street_address_2"
label="street_address_2"
:value="street2"
#input="$emit('update:street2', $event.target.value)"
/>
<!-- <BaseInput
v-model="street2"
name="street_address_2"
label="street_address_2"
:value="address.street2"
#input="$emit('update:street2', $event.target.value)"
/> -->
<BaseInput
v-model="city"
name="city"
label="city"
:value="city"
#input="$emit('update:city', $event.target.value)"
/>
<!-- <BaseInput
v-model="city"
name="city"
label="city"
:value="address.city"
#input="$emit('update:city', $event.target.value)"
/> -->
<BaseInput
v-model="state"
name="state"
label="state"
:value="state"
#input="$emit('update:state', $event.target.value)"
/>
<!-- <BaseInput
v-model="state"
name="state"
label="state"
:value="address.state"
#input="$emit('update:state', $event.target.value)"
/> -->
<BaseInput
v-model="zip"
name="zip"
label="zip"
:value="zip"
#input="$emit('update:zip', $event.target.value)"
/>
<!-- <BaseInput
v-model="zip"
name="zip"
label="zip"
:value="address.zip"
#input="$emit('update:zip', $event.target.value)"
/> -->
<div class="country-select">
<label for="countrySelect">{{ $t('country') }}</label>
<select id="countrySelect" v-model="country" class="form-select" #change="handleChange">
<option v-for="locale in countries" :key="`locale-${locale.code}`" :value="locale.code">
{{ $t('countries.' + locale.code) }}
</option>
</select>
</div>
</div>
<!-- <div class="country-select">
<label for="countrySelect">{{ $t('country') }}</label>
<select id="countrySelect" v-model="address.country" class="form-select" #change="handleChange">
<option v-for="locale in countries" :key="`locale-${locale.code}`" :value="locale.code">
{{ $t('countries.' + locale.code) }}
</option>
</select>
</div>
</div> -->
</BaseCard>
</template>
<script setup lang="ts">
// import {reactive} from 'vue'
import {ref} from 'vue'
// import Address from '../../models/core/Address'
import countries from '../../locales/countries/countries.json'
// defineProps<Address>() // currently not supported
interface Props {
street?: string
street2?: string
city?: string
state?: string
zip?: string | number
country?: string
}
defineProps<Props>()
// const address = reactive<Address>({
// street: '',
// street2: '',
// city: '',
// state: '',
// zip: '',
// country: '',
// })
const street = ref('')
const street2 = ref('')
const city = ref('')
const state = ref('')
const zip = ref('')
const country = ref('')
const emit = defineEmits([
'update:street',
'update:street2',
'update:city',
'update:state',
'update:zip',
'update:country',
])
function handleChange(e: Event) {
emit('update:country', (e.target as HTMLSelectElement).value)
}
</script>
As you can see I tried it with an object being reactive as well as with refs. Both versions don't work.
Here is the UserForm.vue:
<template>
<form id="Form" class="form" #submit.prevent="submit">
<BaseCard>
<div class="card-header">Account Information</div>
<div class="card-body">
<BaseInput
v-model="user.name"
name="name"
label="name"
:error="errors.name"
#validate="validate('name')"
/>
<Address
v-model:street="user.address.street"
v-model:street2="user.address.street2"
v-model:city="user.address.city"
v-model:state="user.address.state"
v-model:zip="user.address.zip"
v-model:country="user.address.country"
/>
</form>
</template>
<script setup lang="ts">
import {reactive, ref, onMounted, unref} from 'vue'
import {User} from '../../models/user/UserTypes'
import Address from '../core/AddressForm.vue'
let isLoading = ref(false)
interface Props {
isLoggedInUser?: boolean
editUser?: boolean
// eslint-disable-next-line vue/require-default-prop
preloadUser?: User
}
const props = withDefaults(defineProps<Props>(), {
isLoggedInUser: false,
editUser: true,
})
const user = reactive<User>({
id: '',
name: '',
address: {
street: '',
street2: '',
city: '',
state: '',
zip: '',
},
})
onMounted(async () => {
isLoading.value = true
console.log('props.preloadUser: ', props.preloadUser)
if (!(Object.keys(props.preloadUser ?? {}).length === 0)) {
Object.assign(user, props.preloadUser)
}
console.log('onMounted-preloaded-user: user: ', user)
isLoading.value = false
})
In the console the onMounted-preloaded-user: user shows the expected user with all the data, it just doesn't reflect in the form as the normal BaseInput for the user.name does.
im new to Vue and trying myself in Vue3 and Vuetify.
Similar to this Post im trying to :key or ref a vue-signature-pad in a for loop.
I initialize an empty Array and push a new element, which adds a new signature.
<template>
<div>
<v-container>
<div class="row" v-for="(input, index) in inputs">
<v-container>
<VueSignaturePad
id="signature"
width="100%"
height="300px"
ref="signaturePad"
/>
</v-container>
<div class="buttons">
<button #click="undo">Undo</button>
<button #click="save">Save</button>
</div>
</div>
<v-row justify="center">
<v-btn #click="addRow"
class="ma-2"
color="blue-grey"
icon="mdi-plus-circle-outline"
></v-btn>
</v-row>
</v-container>
</div>
</template>
<script>
export default {
data: () => ({
inputs: [],
}),
methods: {
addRow() {
this.inputs.push({
name: ''
})
},
undo() {
this.$refs.signaturePad.undoSignature();
},
save() {
const { isEmpty, data } = this.$refs.signaturePad.saveSignature();
alert("Open DevTools see the save data.");
console.log(isEmpty);
console.log(data);
}
}
}
</script>
<style scope>
</style>
In the Post i already mentioned, i tried the Solution from Mathieu Janio.
So if i understand everything right, ref is not working and i have to use :key on the div itself.
So i tried his Solution
<template>
<div
class="row"
v-for="(applicants, index) in applicant_details"
:key="index"
>
<div class="col-sm-4">
<div class="form-group">
<p>Signature for {{ applicants.first_name }}</p>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<VueSignaturePad ref="" />
<button type="button" #click="undo" class="btn btn-warning">
Undo
</button>
</div>
</div>
</div>
</template>
<script setup>
const applicant_details = [
{ first_name: 'john', signature: '' },
];
const undo = () => {
//will undo the signature
};
const save_signature = () => {
//Save the signature
};
</script>
But now im stuck at calling the right "undo"
The signatepad github example uses ref: at the single signaturepad, which is ok.
but not working at the forloop
How do i call now the right function in "undo" for the solution above?
I tried using "this.$.vnode.key" but this gives me an error.
"Uncaught TypeError: Cannot read properties of undefined (reading '$')".
I figured my first way out.
Heres what i have done.
The Signaturepad got an index on the ref.
<VueSignaturePad
:id="'signaturePad' + index"
width="100%"
height="300px"
:ref="'signaturePad' + index"
:options="options"
/>
The "undo" button is giving it "ref" with
<button #click="undo(`signaturePad${index}`)">Undo</button>
And the undo function itself has the first item in its ref array
undo(ref) {
this.$refs[ref][0].undoSignature();
}
Maybe someone has some more efficient way. Feel free :)
while searching, the results should appear as a div like below :
i use jquery to search in table,how to get the result like above.
my component code is:
<div id="modaldash" style={{ display: (searching ? 'block' : 'none') }}>
<p className="font-weight-medium" id="name"> <img id="logo" className="logo" src={jessica} alt="pam-logo" /> Jessica James </p>
<button id="Addlist" onClick={this.onSubmitdata} className="btn info">{this.state.shown ? "Addded" : "Add to list"}</button>
<p id="mailid">jessicajames#gmail.com </p>
<p id= "address">Mountain view,Ave</p>
</div>
its just a static content for css. how to use search and get results like above.
export default function App() {
// considering the data object to search on name
const [searchedData, setSearchedData] = useState([]);
const users = [
{
name: "abc1",
emailid: "abc1#gmail.com",
address: "23rd main, 2nd street"
},
{
name: "adb2",
emailid: "abc2#gmail.com",
address: "23rd main, 2nd street"
},
{
name: "adc3",
emailid: "abc3#gmail.com",
address: "23rd main, 2nd street"
}
];
const handleSearch = event => {
const data = users.filter(
user => user.name.indexOf(event.target.value) !== -1
);
setSearchedData(data);
};
const showSearchedData = () => {
return searchedData.map(user => (
<div key={user.emailid}>
<p className="font-weight-medium" id="name">
{" "}
<img id="logo" className="logo" src="" alt="pam-logo" />
{user.name}
</p>
<button id="Addlist"> Added/ add to list</button>
<p id="mailid">{user.emailid} </p>
<p id="address">{user.address}</p>
</div>
));
};
return (
<div className="App">
<input type="text" onChange={handleSearch} />
<div id="modaldash">{searchedData.length > 0 && showSearchedData()}</div>
</div>
);
}
You can add CSS to make a look and feel like shown in image attached.
Check the working example here https://codesandbox.io/s/falling-sun-r3rim