Alpine JS using wrong id - laravel-livewire

I'm currently making a data table with Laravel Livewire and I use AlphineJS for the confirmation modal. Everything works fine until I paginate to the next page of the data. So here HTML for my delete button for each row :
<a class="mx-1 text-lg" role="button" x-on:click.prevent="onDelete({{ $article->id }})">
<i class="fas fa-trash"></i>
<p x-text="{{ $article->id }}"></p>
</a>
Here s function for onDelete
onDelete(id){
console.log(id);
this.confirmationModal = true;
this.id = id;
},
This is what happens when I try to delete article with an ID of 36, it will console.log the id of the article which is 36
Then I navigate to the next page and try to delete the article with an ID of 46 but the console.log remains 36, I was expecting 46
How to solve this problem?

Change x-on:click to wire:click
<a class="mx-1 text-lg" role="button" wire:click="$emit('onTrashIcon',{{ $article->id }})">
<i class=" fas fa-trash"></i>
</a>
and add listener function x-data + don't forget to x-init="listen()"
listen() {
window.livewire.on('onTrashIcon', articleId => {
this.id = articleId;
this.confirmationModal = true;
})
}

Related

Changes in Ember data does not show the live changes in HTML

In my ember application as shown below when user clicks send the action in component will send the api post request and receive the successful data, can be see in ember inspector data tab, But I need to refresh the page to see newly added item, I tried some example shown in ember guide, nothing helps
My action code is
actions:{
send(Text_Message){
if(Text_Message != null){
console.log(this.chatid);
var data = {
"Message" : Text_Message,
"ChatId" : this.chatid
}
var store = this.get('store').createRecord('message',data)
store.save().then((response)=>{
})
}else{
alert("Type something to send")
}
}
}
handle bar template is
{{#if messages}}
<div>
{{#each messages as |msg|}}
<div class= {{check msg.SenderId userid }}>
{{msg.Message}}
</div>
{{/each}}
</div>
{{else}}
<div class = "groupmessage-no-Msg">
<div class="groupmessage-msg-content"> No Messages </div>
</div>
{{/if}}
<div class = "groupmessage-msg-control">
{{input type="text" placeholder="Type a Message Here... " value=Text_Message}}
<div {{ action 'send' Text_Message}} class="groupmessage-sendbutton groupmessage-sendbutton1" >Send</div>
</div>
you have to push the data you sent to the messages array,
this.messages.push(data);
if it doesn't update use this
this.messages = [...this.messages, { ...data }]

Login with FB button Framework7

im having a problem on implementing the login FB on my framework7 code. It just doesnt display the button, as follows:
<div class="panel panel-left panel-reveal">
<div class="content-block">
<p>Left panel content goes here</p>
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>
<button class="btn-default" scope="public_profile,email" onlogin="checkLoginState();">Login fb</button>
</div>
</div>
Any sugestion on how to tackle this problem?
Does your project is in cordova environment ? , I would suggest You using cordova fb plugin
https://github.com/Wizcorp/phonegap-facebook-plugin
Mine work like a charm
Login page
<li class="item-link">
<a class="signin button button-raised">Sign In</a>
</li>
<li class="item-link">
<a class="registerpage button button-raised">Register</a>
</li>
<li class="item-link">
<span id="facebookLogin" class="button button-fill color-blue">Login With Facebook</span>
</li>
<li class="item-link">
<span id="googleLogin" class="button button-fill color-red">Login With Google</span>
</li>
</ul>
</div>
init function
$('#facebookLogin').on('click', function () {
facebookLogin();
})
facebookLogin function
function facebookLogin() {
facebookConnectPlugin.login(["public_profile", "user_birthday", "user_hometown", "email"],
fbLoginSuccess,
function (error) { app.app.alert(JSON.stringify(error)) }
);
var fbLoginSuccess = function (userData) {
// use token from userData to your existing login system
//userData.authResponse.accessToken
};
}

Selenium Grayed out Button

Hi I'm trying to click on this button that stays disabled until you fill in other fields. I am working with firefox. My script fills out those fields and the button is now clickable with my mouse. But when I try to click that element through selenium I get an error
WebDriverException: Message: Element is not clickable at point (281.8333282470703, 14.149993896484375). Other element would receive the click: <li ng-class="{active: $state.includes('urlAdm')}" id="adm-menu"></li>
Here is the html for the button.
<div class="col-xs-offset-2 col-xs-5">
<button type="submit" class="btn btn-primary ng-binding" ng-disabled="!userForm.$valid || user.deleted_at" disabled="disabled">
<i class="fa fa-check-square-o fa-fw"></i>
Create
</button>
<!-- ngIf: isAddUser() --><button ng-if="isAddUser()" type="button" class="btn btn-default ng-scope" ng-click="resetForm()">
<i class="fa fa-eraser fa-fw"></i>
Clear
</button><!-- end ngIf: isAddUser() -->
<!-- ngIf: !user.deleted_at && user.id !== currentUser.id && user.id -->
<!-- ngIf: user.deleted_at -->
</div>
I've tried regularly clicking on the button and doing it through actions but neither work.
Here is the code
element = driver.find_element_by_xpath("//*[#id='user-editor-1']/form/div[5]/div/button[1]")
ActionChains(driver).move_to_element(element).click().perform()
Any help would be greatly appreciated. Thanks!
You should try to click using execute_script() as below :-
element = driver.find_element_by_xpath("//button[contains(.,'Create')]")
driver.execute_script("arguments[0].click();",element)
Hope it helps....:)

How to make modals which have routes like Trello in Emberjs

I want to know how we can make modals which have routes.
In Trello, whenever you click on a card, the route changes from abc.com/b/personal to abc.com/c/some-random-string and the card opens in a modal. Also, when you close the modal, you get redirected to the previous url (abc.com/b/personal).
I want to know how can we achieve this using Emberjs.
Example: https://trello.com/b/ezWgKsol/sales-enterprise-feature-requests-sample
Here is my modal (using foundation) where we delete a record:
<div class="reveal" id="deleteLocationModal" data-reveal>
<div class="row">
<div class="columns">
Are you sure you want to delete this location?
</div>
</div>
<div class="row">
</div>
<div class="row">
<div class="columns">
<button id="cancelButton" class="secondary button" data-close type="button">Cancel</button>
<button id="deleteButton" class="button" {{action "deleteLocation" model}} data-close type="button">Delete</button>
</div>
</div>
</div>
The router has the falling in the actions hash:
actions: {
deleteLocation(model) {
Ember.assert("Params must be provided", model);
model.save().then(( /* response */ ) => {
this.transitionTo('locations'); //locations is my index page.
//flash message to inform the user of success.
});
}, (error) => {
//handle error.
// display flash message
// rollback any dirty attributes
});
}
I hope this helps,
Jeff

Bootstrap accordion with ember

Hi there i have a small question that belonging to my small ember application.
JSFiddle upload is here. I used bootstrap accordion to visualize my tickets. When i click on the "click" it adds another accordion into my view. But sadly it cannot be opened or used. Every accordion i dynamically created cannot be opened or closed. There is no error or exception thrown and from my point of view everything should work fine. My click-function looks like this:
click: function() {
this.counter++,
name = this.name+this.counter.toString(),
tre = App.Ticket.create({
Text: "try",
id: name
});
this.pushObject(tre);
}});
The belonging html is here:
<div class="accordion-group">
{{#each content}}
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" {{bindAttr href="id"}}>
Ticket ID/Störfall
</a>
</div>
<div {{bindAttr id="id"}} class="accordion-body collapse in ">
<div class="accordion-inner">
{{Text}}
</div>
</div>
{{/each}}
</div>
I hope you can help me.
You can add an action helper to the accordion link title
<a class="accordion-toggle" data-toggle="collapse"
data-parent="#accordion2"
{{bindAttr href="item.id"}}
{{action "click" item target="view"}}>
Ticket ID/Störfall
</a>
Then implement a click handler event in your view
App.TicketView = Em.View.extend({
click:function(context) {
var el = this.$('a[href='+context.get('id')+']');
el.toggleClass('collapsed');
this.$('#'+el.attr('href')).toggleClass('in');
}
});
Here's a working fiddle