I have a function like this:
scope.addReply = function(el) {
createCommentFactory.saveComment(scope.form.reply[el.pivot.comment_id], el.pivot.project_id, el.pivot.comment_id, el.level + 1)
.success(function(data) {
//ADD REPLY TO CLIENT SIDE
scope.comments.splice(scope.comments.indexOf(el) + 1, 0, data);
//TOGGLE FORM AFTER SUCCESSFUL AJAX REQ
el.formWhat = !el.formWhat;
})
.error(function(data) {
console.log(data);
});
// RESET REPLY TEXT AREA
scope.form.reply = "";
};
html:
<div dir-paginate="x in comments | itemsPerPage: commentsPerPage">
<form ng-submit="addReply(x)" class="dd animated slideInDown" novalidate>
<ng-form name="replyForm">
<div class="form-group">
<text-angular name="replyText<%x.pivot.comment_id%>" ta-default-wrap="span" ta-max-text="600" ta-min-text="15" ta-text-editor-class="form-control myform1-height" ta-html-editor-class="form-control myform1-height" ta-toolbar="[['bold','italics']]" style="min-height: 100px; color:red;"
ng-model="form.reply[x.pivot.comment_id]" required></text-angular>
<p style="color:red" ng-show="replyForm.replyText<%x.pivot.comment_id %>.$error.taMaxText">
Text should not be more then 600 characters.</p>
<p style="color:red" ng-show="replyForm.replyText<%x.pivot.comment_id %>.$error.taMinText">
Text should be at last 15 characters.</p>
</div>
<div class="form-group">
<input addreply ng-disabled="replyForm.replyText<%x.pivot.comment_id%>.$invalid" class="btn btn-default pull-right"
type="submit" value="Send"/>
</div>
</ng-form>
</form>
</div>
Function, after ajax is successful, will push item below the comment I reply inside: scope.comments... Problem now is that I can't submit form which I added with ajax request because form is not created by ng-repeat, for is created after ajax request like this: scope.comments.splice(scope.comments.indexOf(el) + 1, 0, data);
Related
I have to pass the value to controller page using link format.
My view page code for link:
<form action="<?=site_url('Account_Master/Tax_Save')?>" method="POST">
<head><h5><center>TAX SLAB ENTRY</center></h5><button type="submit" class="btn bg-slate"><i class="icon-file-plus position-left"></i>Ok</button>
<a id="button" method="POST" href="<?=site_url('Account_Master/get_data')?>" class="btn bg-info"><i class="icon-book3 position-left"></i> View All</a>
</head>
<div id="item1">
Tax Type: <input type="text" style="height: 28px; width:250px; " id="taxtype" name="taxtype">
</div>
When i clicked the view all button type link the value of the tax type should be pass to controller page.But i have written code to post the value but the value is not passed.
My controller code:
public function get_data(){
$tax = $this->input->post('taxtype');
print_r($tax);
$data['query']= $this->db->query("SELECT * FROM tax where taxtype ='$tax' ")->row();
$this->load->view('Account_Master/Tax_Setting1', $data, FALSE);
}
I have so far tired this code the value of the taxtype is not passed to the controller
hello I hope there is a problem with your code if I may say
Edited Part
Base on getting the input value which is not possible on button click can be done using jquery js library
html file
<form id="form" action="<?php echo site_url('Account_Master/Tax_Save');?>" method="POST">
<head>
<h5>
<center>TAX SLAB ENTRY</center>
</h5>
<button type="submit" class="btn bg-slate">
<i class="icon-file-plus position-left"></i>
Ok
</button>
<a id="button" href="<?php echo site_url('Account_Master/get_data/');?>" class="btn bg-info">
<i class="icon-book3 position-left"></i>
View All
</a>
</head>
<div id="item1">
Tax Type:
<input type="text" style="height: 28px; width:250px; " id="taxtype" name="taxtype">
</div>
</form>
Place this code just before your closing body tag
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#form').on('click', '#button', function(event){
event.preventDefault();
var form_box = $(this).parents('#form'),
tax_value = form_box .find('input').val(),
link_url = $(this).attr('href'),
url = link_url+tax_value;
form_box.attr('action', url);
form_box.submit()
})
})
</script>
Then in your controller,
either you do this
public function get_data($tax_value){
$tax = $tax_value;
print_r($tax);
$data['query']= $this->db->query("SELECT * FROM tax where taxtype ='$tax' ")->row();
$this->load->view('Account_Master/Tax_Setting1', $data, FALSE);
}
OR
public function get_data(){
$tax = $this->input->post('taxtype');
print_r($tax);
$data['query']= $this->db->query("SELECT * FROM tax where taxtype ='$tax' ")->row();
$this->load->view('Account_Master/Tax_Setting1', $data, FALSE);
}
I hope this help you if not let me know your argument okay... I am here to help
I am new to AJAX and I am trying to send some data to the controller using the AJAX. on clicking the button "Start Event", nothing is happening..
This is my jsp page where I have written the AJAX code
<c:forEach items="${scheduledEvents}" var="event">
<div class="col-md-3" id="eventId">
<div class="card-counter primary">
<div id="head" class="card-counter head-color"></div>
<span class="count-head">${event.eventName}</span>
<br>
<span class="count-name">Date : ${event.date}</span>
<span class="count-name">Location : ${event.location}</span>
<span class="count-name">Hosted By : ${event.hostName}</span>
<span class="count-name">Description : ${event.description}</span>
<br>
<br>
<div class="count-join">
<button class=" btn" id="${event.linkId}" style="background-color: #cc3300;"><font style="color: white;">Start Event</font></button>
</div>
</div>
</div>
</c:forEach>
<script type="text/javascript">
$(function() {
$('.count-join').on('click',function(){
var eventData = $(this).attr("id")
.ajax({
url : 'startEvent?data=' +eventData,
type : 'GET',
contentType : 'application/json',
success : function(data){
$
.get(
'${pageContext.request.contextPath}/startEvent',
function(data,status) {
$("#eventId").html(data);
}
);
}
});
});
});
</script>
And this my controller mapping
#RequestMapping(value="/dashBoard/startEvent")
public ModelAndView startScheduledEvent(#RequestParam("data")String data)
{
System.out.println(data);
return new ModelAndView("DashBoard");
}
Where am I wrong? please give some detailed explanation as I do not know much about AJAX. Thanks in advance.
As per you controller #RequestMapping, you have missed the /dashBoard in ajax call.
I created a simple real-time chat application using vue js in laravel.
I am having a problem with the automatic scroll of the div when there is a new data.
What I want is the div to automatically scroll down to the bottom of the div when there is a new data.
Here is my code so far.
Chat.vue file
<template>
<div class="panel-block">
<div class="chat" v-if="chats.length != 0" style="height: 400px;" id="myDiv">
<div v-for="chat in chats" style="overflow: auto;" >
<div class="chat-right" v-if="chat.user_id == userid">
{{ chat.chat }}
</div>
<div class="chat-left" v-else>
{{ chat.chat}}
</div>
</div>
</div>
<div v-else class="no-message">
<br><br><br><br><br>
There are no messages
</div>
<chat-composer v-bind:userid="userid" v-bind:chats="chats" v-bind:adminid="adminid"></chat-composer>
</div>
</template>
<script>
export default {
props: ['chats','userid','adminid'],
}
</script>
ChatComposer.vue file
<template>
<div class="panel-block field">
<div class="input-group">
<input type="text" class="form-control" v-on:keyup.enter="sendChat" v-model="chat">
<span class="input-group-btn">
<button class="btn btn-primary" type="button" v-on:click="sendChat">Send Chat</button>
</span>
</div>
</div>
</template>
<script>
export default{
props: ['chats','userid','adminid'],
data() {
return{
chat: ''
}
},
methods: {
sendChat: function(e) {
if(this.chat != ''){
var data = {
chat: this.chat,
admin_id: this.adminid,
user_id: this.userid
}
this.chat = '';
axios.post('/chat/sendChat', data).then((response) => {
this.chats.push(data)
})
this.scrollToEnd();
}
},
scrollToEnd: function() {
var container = this.$el.querySelector("#myDiv");
container.scrollTop = container.scrollHeight;
}
}
}
</script>
I am passing a div id from the Chat.vue file to the ChatComposer.vue file.
As you can see in the ChatComposer.vue file there is a function called scrollToEnd where in it gets the height of the div id from Chat.vue file.
When the sendchat function is triggered i called the scrollToEnd function.
I guess hes not getting the value from the div id because I am getting an error - Cannot read property 'scrollHeight' of null.
Any help would be appreciated.
Thanks in advance.
the scope of this.$el.querySelector will be limited to only ChatComposer.vue hence child component can not able to access div of parent component #myDiv .
You can trigger event as below in ChatComposer
this.$emit('scroll');
In parent component write ScollToEnd method and use $ref to assign new height
<chat-composer v-bind:userid="userid" v-bind:chats="chats" v-bind:adminid="adminid" #scroll="ScollToEnd"></chat-composer>
..
I am using AngularJS v1.2.15 and angular-ui / ui-select. My select HTML is:
<div class="form-group col-md-3">
<div class="input-group select2-bootstrap-append">
<ui-select ng-model="modelOwner.selected" theme="select2" class="form-control">
<match placeholder="Select Owner">{{$select.selected.name}}</match>
<choices repeat="item in owner | filter: $select.search">
<span ng-bind-html="item.name | highlight: $select.search"></span>
</choices>
</ui-select>
<span class="input-group-btn">
<button ng-click="modelOwner.selected = undefined" class="btn btn-danger">
<span class="glyphicon glyphicon-trash"></span>
</button>
</span>
</div>
</div>
My call in controller is:
$scope.modelOwner = {};
OwnersFactory.query({}, function (data) {
$scope.owner = data;
});
My service code:
bootstrapApp.factory('OwnersFactory', function ($http,$state,serviceUrl,$resource,$log) {
return $resource(serviceUrl + 'owner/:id', {}, {
show: { method: 'GET', params: {}, isArray: false }
})
});
Now, in my form i can view the values only after entering at least a single character. I want this select dropdown to display values just by clicking on the dropdown (not by entering any character.)
Possible Solution: if i could load my state only after all the AJAX calls have been made.
Please help me out here.
if you are using ui-router you can use resolve on each state, so that the call is resolved before initializing the controller
https://github.com/angular-ui/ui-router/wiki#resolve
I am trying to make a form submit through ajax and the JsHelper from CakePHP 1.3
I try to make a call to /eng/feedbacks/submit_feedback but instead in the console, i see a post to http://lang/eng/pa/homepage instead. The result returned is another instance of that page, rather than anything else.
This seems to be irrelevant to whether such submit_feedback exists or not. I have started that action with die("test"); and it doesn't change anything.
why is that, what is going on?
the form is in my layout (as i want it to be in my footer). Runs when the url is /eng/pa/homepage
Form code:
echo $this->Form->create('Feedback', array('url'=>array( 'controller'=>'feedbacks', 'action'=>'submit_feedback')));
echo $this->Form->input('Feedback.content', array('label'=>false, 'type'=>'textarea'));
echo $this->Js->submit('Save', array('class'=>'button blue',
'before'=>$this->Js->get('#sending')->effect('fadeIn'),
'success'=>$this->Js->Get('#sending')->effect('fadeOut'),
'update'=>'#success'
));
echo $this->Form->end();?>
<div id="success">xx</div>
In that #success DIV i get a related full page, rather than what I have defined in the controller action
Controller method:
function submit_feedback(){
if(!empty($this->data)){
$this->Feedback->set($this->data);
if($this->Feedback->validates()){
if($this->Feedback->save($this->data)){
// AJAX
if($this->RequestHandler->isAjax()){
$this->render('/feedbacks/success', 'ajax');
}else{
die('not ajax');
}
}
}
}
}
And the success template is:
<p style="background: lightgreen">Purple cow!</p>
What am i doing wrong?
NOTE: If I run the same form from the /eng/feedbacks/submit_feedback page, It works exactly as it should through ajax, and my database gets updated, i get the necessary 'success' template loaded and all is shiny and happy.
UPDATE: FORM SOURCE COUDE GENERATED:
<form accept-charset="utf-8" action="/eng/feedbacks/submit_feedback" method="post" id="FeedbackReadForm">
<div style="display: none;">
<input type="hidden" value="POST" name="_method">
</div>
<input type="hidden" id="FeedbackUserId" value="141" name="data[Feedback][user_id]">
<div class="input radio">
<input type="hidden" value="" id="FeedbackType_" name="data[Feedback][type]">
<input type="radio" value="suggestion" id="FeedbackTypeSuggestion" name="data[Feedback][type]">
<label for="FeedbackTypeSuggestion">Suggestion</label>
<input type="radio" value="problem" id="FeedbackTypeProblem" name="data[Feedback][type]">
<label for="FeedbackTypeProblem">Poblem</label>
<input type="radio" value="opinion" id="FeedbackTypeOpinion" name="data[Feedback][type]">
<label for="FeedbackTypeOpinion">Other Opinion</label>
</div>
<div class="input textarea">
<textarea id="FeedbackContent" rows="6" cols="30" name="data[Feedback][content]"></textarea>
</div>
<div style="margin-top: 17px; margin-right: 50px;" class="right">
<a onclick="javascript: closeFeedbackPuller(); return false;" href="#">Cancel</a>
</div>
<div class="submit">
<input type="submit" value="Save" id="submit-396027771" class="button blue">
</div>
</form>
UPDATE 2: JS generated:
$(document).ready(function () {
$("#submit-396027771").bind("click", function (event) {
$.ajax({
beforeSend:function (XMLHttpRequest) {
$("#sending").fadeIn();
},
data:$("#submit-396027771").closest("form").serialize(),
dataType:"html",
success:function (data, textStatus) {
$("#sending").fadeOut();
$("#success").html(data);
},
type:"post",
url:"\/eng\/pa\/homepage"
});
return false;
});
});
I see that the url is wrong, even thought the form url was right. How can this be resolved?
echo $this->Js->submit('Save', array('class'=>'button blue',
'before'=>$this->Js->get('#sending')->effect('fadeIn'),
'success'=>$this->Js->Get('#sending')->effect('fadeOut'),
'url' => '/eng/feedbacks/submit_feedback',
'update'=>'#success'
));
That may fix your problem, but I am not 100% sure. It seems that the Js->submit() method accepts a lot of the Form helper methods.