not able to clear the data using angular Js. I have assigned the value to null and empty. when i debug it the values are getting cleared but in front end the values are not clearing
$scope.callCancel = function() {
$scope.riskObj.areaName ="";
$scope.areaName ="";
$scope.riskObj.areaDesc ="";
$scope.areaDesc =""
html code:
<div ng-if="type == 1"class="col-md-3">
<h5><strong>Risk Area Name</strong></h5>
<div class="form-group">
<input type="text" class="form-control input-sm text-field" data-ng-model="areaName" ng-keyup="getChangedAreaName(areaName)" ng-disabled="type == 2">
</div>
</div>
<div ng-if="type == 1" class="col-md-6">
<h5><strong>Risk Area Description</strong></h5>
<div class="form-group">
<input type="text" class="form-control input-sm text-field" data-ng-model="areaDesc" ng-keyup="getChangedAreaDesc(areaDesc)" ng-disabled="type == 2">
</div>
</div>
<div ng-if="type == 1" style="text-align:right;">
<img src="core/static/images/submit-btn.png" data-ng-click="updateRiskArea(areaName,areaDesc,this)" />
<img src="core/static/images/cancel-btn.png" data-ng-click="callCancel()"/>
</div>
I need to clear the values I enter in the front end. Using the above code I am able to clear already entered data. But once I modify the value and call cancel function the values are not getting cleared
The main issue is you're not setting your ng-model accurately. For example, it should bind to riskObj.areaName as that is your data model, not just areaName. Additionally, you should be initializing these objects in your scope somewhere, like $scope.riskObj = {areaName:'', areaDesc:''};
There are a few issues with your code other than that.
Utilize your anchor tags to be ng-click. Don't have an anchor with a hash for HREF and then put an ng-click inside on an image. Instead, just do something like <a href ng-click="...
You have 3 divs in a row with ng-if="type==1" - why not just put those 3 in a <div class="row" ng-if="type==1"> - cleaner and easier to read/maintain
Inside those conditionals, you have a ng-disabled="type==2" -- that will never ever do anything since the div will ONLY show if type=1
angular.module('selectExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.type = 1;
$scope.riskObj = {
areaName: '',
areaDesc: ''
};
$scope.callCancel = function() {
$scope.riskObj.areaName = "";
$scope.areaName = "";
$scope.riskObj.areaDesc = "";
$scope.areaDesc = ""
}
}]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.10/angular.min.js"></script>
<div ng-app="selectExample">
<div ng-controller="ExampleController">
<div class='row' ng-if="type == 1">
<div class="col-md-3">
<h5><strong>Risk Area Name</strong></h5>
<div class="form-group">
<input type="text" class="form-control input-sm text-field" data-ng-model="riskObj.areaName">
</div>
</div>
<div class="col-md-6">
<h5><strong>Risk Area Description</strong></h5>
<div class="form-group">
<input type="text" class="form-control input-sm text-field" data-ng-model="riskObj.areaDesc">
</div>
</div>
<div style="text-align:right;">
<a href data-ng-click="callCancel()">cancel</a>
</div>
</div>
</div>
Related
I am using the owl-date-time module in my application to get date-time parameters in two fields. However, I am getting the value in a list with an additional null value in the payload.
Also, I wish to convert the value to epoch time to meet the API requirements.
In HTML Component:
<div class="form-group row">
<label class="col-md-3 col-form-label text-right">
Start Time
<span class="colorRed">*</span>
</label>
<div class="col-lg-5 col-sm-11">
<input type="text" id="start_time" style="height: 36px;"
class="form-control" [selectMode]="'rangeFrom'" name="start_time"
placeholder="Start Time" [(ngModel)]="startTime"
[owlDateTimeTrigger]="dt1" [owlDateTime]="dt1"
(change)="getTime(startTime,dt1)" [max]="maxFrom"
autocomplete="off" required>
<owl-date-time #dt1></owl-date-time>
</div>
<!---->
</div>
<div class="form-group row">
<label class="col-md-3 col-form-label text-right">
Stop Time
<span class="colorRed">*</span>
</label>
<div class="col-lg-5 col-sm-11">
<input type="text" id="stop_time" style="height: 36px;"
class="form-control" [selectMode]="'rangeTo'" name="stop_time"
placeholder="End Time" [(ngModel)]="stopTime"
[owlDateTimeTrigger]="dt2" [owlDateTime]="dt2"
(change)="getTime(stopTime,dt2)" [min]="minTo"
autocomplete="off" required>
<owl-date-time #dt2></owl-date-time>
</div>
</div>
</div>
In Typescript, I am calling this function to do the conversion. But I do not think that the function is getting called as I am unable to get any console logs.
TS Code
getTime(t, selectMode) {
console.log("Hello Chuckles");
let tempRangeFrom, tempRangeTo;
t.forEach(element => {
if (typeof (element) != 'undefined' && element != null) {
if (element[1] != null) {
console.log("FROM!##$%^&*()");
tempRangeFrom = element.getTime(); // Date To TimeStamp
this.minTo = new Date(tempRangeFrom); // TimeStamp to Date
this.minTo.toGMTString();
} else {
tempRangeTo = element.getTime();
this.maxFrom = new Date(tempRangeTo);
this.maxFrom.toGMTString();
}
}
});
}
Screenshot for date-picker:
Payload:
You can simply do this:
const date = new Date()
console.log(new Date(date).getTime())
You can also check this link if the above code doesn't help.
My view:
<div class="col-md-3">
<div class="form-group">
<label>Employee Id</label>
<input type="text" class="form-control" placeholder="Enter employee id" name="empid">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Employee Name</label>
<input type="text" class="form-control" placeholder="Enter employee name" name="empname">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Order Number</label>
<input type="number" class="form-control" placeholder="Enter order number" name="ordernumber" value="<?php echo $order_number;?>">
</div></div>
<div class="col-md-3">
<div class="form-group">
<label></label>
<a onclick="myFunctionfirst()" class="form-control">Proceed to order Create</a>
</div></div>
Once you click on 'proceed to order create' the second row is created. I want this to happen only when the first 3 fields in first row are filled. Please suggest on this
And this is my controller:
public function index()
{
$empid = $_POST['empid'];
If ($empid == ""){
$this->load->model('invoice_model');
$data['stat']= $this->invoice_model->get_stationary();
$data['order_numbers']= $this->invoice_model->get_countnumber();
$data['order_number']= $data['order_numbers'][0]->count+1;
$data['page']='invoice/invoice_view';
$this->load->view("template",$data);
}
}
And it's throwing an error undefined index empid
Welcome to stackoverflow. what you can do is save the input as a variable Store input from a text field in a PHP variable
this method is however a bit unsafe. to secure the input you can use https://www.w3schools.com/php/func_string_htmlspecialchars.asp
https://www.php.net/manual/en/function.htmlspecialchars.php
and once you have the variables just simply check if the variable is empty or not
public function index()
{
$firstname = $_POST['firstname'];
If ($firstname != ""){
$this->load->model('invoice_model');
$data['stat']= $this->invoice_model->get_stationary();
$data['order_numbers']= $this->invoice_model->get_countnumber();
$data['order_number']= $data['order_numbers'][0]->count+1;
$data['page']='invoice/invoice_view';
$this->load->view("template",$data);
}
}
$_POST is how the data is being send. here they explain the difference between POST and GET https://www.quora.com/What-is-the-difference-between-PHPs-get-method-post-method
'firstname' is the name of the input. in your case its <input type="text" class="form-control" placeholder="Enter employee id" name="empid"> so it should be $_POST['empid']
the data is being send with the submit button. instead of using the <a> tag you should use the <button type="submit"> tag also, wrap the inputs in a form tag.
I am working on a project with Symfony 2.8. My main goal is to create a dynamic calendar based on Fullcalendar library.
I add my events called "dispos" (avalabilities in English) and "Rdvs" (appointments" in English) through a Json request and ajax. This works fine.
Now, I would like to transform availabilites into appointements (which are both considered as events in Fullcalendar).
E.g : When someone clicks on one availability a modal shows up, then the person fills the form in it and clicks "save" button.
When the "save" button is clicked, all informations entered in the form are sent and saved (through a Json request) into my Database and the appointment is taken
--> all events of the current should be reloaded through ajax, the event should be displayed with the title of the event entered (name of the patient) and the modal should contain all informations given/wrote before "save" action.
I tried to do it but my ajax is not working since events do not reload after saving everything else is working.
Anyway, I think I did it wrong somewhere. The code I will show you in my Controller returns a view because I didn't manage to return a response (+ I think routing or something is bad but don't know how to fix it...)
Any clue or advice woud be really appreciated :)
So here is my code :
TakeRdvAction in my controller :
/* ----------------- /
/ --- TAKE RDV ---- /
/ ----------------- */
public function takeRdvAction(){
$request = $this->get('request_stack')->getCurrentRequest();
parse_str($request->getContent(), $myArray);
/*$request->isXmlHttpRequest()*/
if (1) {
$dateHeureDispo=$myArray['heureDispo'];
$dateDispo= new \DateTime($dateHeureDispo);
$heureDispo = $dateDispo->format('H:i');
$dateDispo=$dateDispo->format('d-m-Y');
$civilite=$myArray['civilite'];
$nom=$myArray['inputNom'];
$prenom=$myArray['inputPrenom'];
$naissance=$myArray['birth'];
$email=$myArray['email'];
$tel=$myArray['tel'];
$telFixe=$myArray['telFixe'];
$adresse=$myArray['adresse'];
$cp=$myArray['cp'];
$ville=$myArray['ville'];
$pays=$myArray['pays'];
$medecin_traitant=$myArray['medecin_traitant'];
$ame=$myArray['ame'];
$cmu=$myArray['cmu'];
$takeRDv="http://connect.mysite.com/nameofapi2/takeappt?center=13&motive=238&prenom=".urlencode($prenom)."&nom=".urlencode($nom)."&email=".urlencode($email)."&birthdate=".$naissance."&address=".urlencode($adresse)."&cp=".$cp."&city=".urlencode($ville)."&country=".urlencode($pays)."&tel=".$tel."&titre=1&source=1&origine=1&daterdv=".$dateDispo."&time=".$heureDispo."&slot=1%E1%90%A7&civilite=".$civilite."&origin=smwh&referer=1";
$streamContext = stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
]);
$json = file_get_contents($takeRDv, false, $streamContext);
$response = new jsonResponse();
$response->setContent($json);
return $this->indexAction();
}
else {
return new response("Ajax request failed");
}
}
If I put if ($request->isXmlHttpRequest()), the controller goes directly to "else" end returns "Ajax request failed"
Ajax.js file (It's the last ajax function we are talking about):
$(document).ready(function () {
/* TakeRdvs */
$("#monBouton").click(function(){
if (nom.value != "" && prenom.value != "" && email.value != "")
{
$.ajax({
url: "{{ path('takeRdv') }}",
method: 'POST',
data: {},
success: function(data) {
$("#calendarModal").modal('hide');
$("#calendarModal").on('hidden.bs.modal', function (e) {
$('#calendar').fullCalendar('refetchEvents');
});
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
alert('Error: ' + errorThrown);
}
});
}
else if (nom.value == "")
{
alert('Veuillez renseigner le Nom');
return false;
}
else if (prenom.value == "")
{
alert('Veuillez renseigner le prénom');
return false;
}
else if (email.value == "")
{
alert("Veuillez renseigner l'adresse mail");
return false;
}
});
});
Other ajax functions work just fine, I made them after trying to take an appointment on an availability. When I implemented FosJsRouting, I thought it would be easier to try to make my takeRdvs action work. But the truth is, I don't know how to do it since it's a different action from the others and I am lost now :'(
My modal showing up when a event is clicked (got cut in several part sorry could not fix it):
×
close
<div class="form-group">
<div class="col-sm-12">
<h4 id="modalTitle" class="modal-title modify"></h4>
</div>
</div>
<div class="col-sm-4 form-group">
<label for="motif">
Motif de la consultation :
</label>
<select class="form-control" id="motif" data-placeholder="Choisissez un motif" style="width: 100%;" name="motif"> {# multiple data-max-options="1" #}
<option value="238"> Bilan de la vue</option>
<option value="Visite de controle"> Visite de contrôle</option>
<option value="Chirurgie réfractive"> Chirurgie réfractive</option>
<option value="Rééducation visuelle"> Rééducation visuelle</option>
<option value="Urgences"> Urgences</option>
</select>
</div>
<div class="form-group create">
<div class="col-sm-2">
<label class="control-label" for="civilite">Civilité</label>
<select class="custom-select" id="civilite" name="civilite">
<option value="Mme">Mme</option>
<option value="M">M.</option>
</select>
</div>
<div class="col-sm-5">
<label class="control-label" for="inputNom">Nom</label>
<input name="inputNom" type="text" class="form-control" id="inputNom" placeholder="Doe" required >
</div>
</div>
<div class="form-group">
<div class="col-sm-5 create">
<label class="control-label" for="inputPrenom">Prénom</label>
<input name="inputPrenom" type="text" class="form-control" id="inputPrenom" placeholder="Jane" required >
</div>
</div>
<div class="form-group">
<div class="col-sm-6">
<label class="control-label" for="email">Email</label>
<input name="email" type="email" class="form-control" id="email" placeholder="jane.doe#example.com" required >
</div>
</div>
{# fin de la condition #}
<div class="form-group">
<div class="col-sm-6">
<label class="control-label" for="naissance">Date de naissance</label>
<input name="birth" type="text" class="form-control" id="naissance" placeholder="01-01-2001" required>
</div>
<div class="col-sm-6">
<label class="control-label" for="tel">Mobile</label>
<input name="tel" type="tel" class="form-control" id="tel" placeholder="0607080910" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-6">
<label class="control-label" for="telFixe">Téléphone fixe</label>
<input name="telFixe" type="tel" class="form-control" id="telFixe" placeholder="0101010101">
</div>
</div>
<div class="form-group">
<div class="col-sm-5">
<label class="control-label" for="adresse">Adresse</label>
<input name="adresse" type="text" class="form-control" id="adresse" placeholder="1 Bd de Strasbourg 83000 Toulon" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<label class="control-label" for="cp">Code postal</label>
<input name="cp" type="text" class="form-control" id="cp" placeholder="83000" required>
</div>
</div>
<div class="form-group">
<div class="form-group">
<div class="col-sm-4">
<label class="control-label" for="ville">Ville</label>
<input name="ville" type="text" class="form-control" id="ville" placeholder="Toulon" required>
</div>
</div>
</div>
<div class="form-group">
<div class="form-group">
<div class="col-sm-4">
<label class="control-label" for="pays">Pays</label>
<input name="pays" type="text" class="form-control" id="pays" placeholder="France" required>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-6">
<label class="control-label" for="medecin_traitant">Médecin traitant</label>
<input name="medecin_traitant" type="text" class="form-control" id="medecin_traitant" placeholder="Dr Bicharzon" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-6">
<label class="control-label" for="ame">
Bénéficiare de l'AME ?
</label>
<select class="form-control" name="ame" title="ame" id="ame" required>
<option value="oui">Oui</option>
<option value="non">Non</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-6">
<label class="control-label" for="cmu">
Bénéficiare de la CMU ?
</label>
<select class="form-control" name="cmu" title="cmu" id="cmu" required>
<option value="oui">Oui</option>
<option value="non">Non</option>
</select>
</div>
</div>
<input title="heureDispo" class="visually-hidden form-control" name="heureDispo" type="text" id="heureDispo">
<div class="form-group boutonsModale col-sm-6">
<button type="button" class="btn btn-default btn-danger" data-dismiss="modal">Annuler</button>
<button type="submit" class="btn btn-primary" id="monBouton">Enregistrer</button>
</div>
</form>
</div>
{#{% endfor %}#}
<div class="modal-footer paddingTop">
{#<button type="button" class="btn btn-default btn-danger" data-dismiss="modal">Annuler</button>#}
{#<input type="submit" class="btn btn-primary">Enregistrer</input>#}
{#<button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>#}
</div>
</div>
</div>
</div>
</div>
Routing.yml :
Take RDV
take_rdv:
path: /prise-rdv
defaults: {_controller: RdvProBundle:Default:takeRdv}
methods: [POST]
options:
expose: true
I don't know how to change the route if I need to... + I would like the route no to show like the other routes I created but as it's coded now, it's shown...
I am junior junior as dev so I a sorry if my code is not clean :s
Thank you in advance for all the help you will provide.
It is huge. I'm not sure about your problem(s?) but if I understand :
First problem :
ajax is not working since events do not reload
If your #button is replaced in your page after your first call, the attached event is destroyed. Change your listener :
$("#monBouton").click(function(){
by
$('body').on('click', '#monBouton', function () { will solve the problem.
Second problem :
If I put if ($request->isXmlHttpRequest()), the controller goes directly to "else"
I suggest to pass $request as argument of your action and just put your condition within an if statement :
public function takeRdvAction(Request $request)
{
if ($request->isXmlHttpRequest()) {
[...]
}
}
Thirdly :
To use FosJsRouting, you exposed your route in your yaml. That's good. To use it in javascript, you have to include the given script in your base.html.twig and use Routing.generate just as defined in the doc :
$.ajax({
url: Routing.generate('take_rdv', {/* $(yourform).serialize() ?*/}),
method: 'POST',
data: {},
success: function(data) {
$("#calendarModal").modal('hide');
$("#calendarModal").on('hidden.bs.modal', function (e) {
$('#calendar').fullCalendar('refetchEvents');
});
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
alert('Error: ' + errorThrown);
}
});
Update
With my suggestions, you've to change how you use $request in your action :
$myArray = $request->request->all();
$civilite=$myArray['civilite'];
[...and so on...]
Bonus : Symfony is a powerfull framework. I suggest you to learn about using this framework and especially, in your case, about Forms
enjoy :)
UPDATE 2
if ($request->isXmlHttpRequest()) { is never true cause you are not doing an ajax call. I just see that, but your button is of type submit then, your browser send a basic HTTP request.
Add this to your js code :
$('body').on('click', '#monBouton', function (event) {
event.preventDefault();
[...$.ajax blablabla]
});
In our rather complex form I found that the ng-dirty flag being applied when nothing was actually changed. I originally thought the problem was in the placeholder attribute on the input text, but now even with this attribute removed the flag is still being set when nothing was changed. Is it some sort of a bug? If yes, what is the solution? The problematic elements defined as following
<div class="form-group" ng-show="isNew">
<div class="controls">
<label class="control-label col-md-3 col-lg-3" title="#Labels.operatorCode">#Labels.operatorCode:</label>
<div class="col-md-6 col-lg-6">
<input type="text" name="opCode" id="opCode" ng-model="currentOperator.opCode"
class="form-control" ng-maxlength="6" ng-show="isNew"
ng-required ="isNew" />
<div class="field-validation-error" >
<span ng-show="form.editOperatorGeneralForm.opCode.$error.required && form.editOperatorGeneralForm.opCode.$dirty">#String.Format(Messages.isRequired, Labels.operatorCode)</span>
<span ng-show="form.editOperatorGeneralForm.opCode.$error.maxlength && form.editOperatorGeneralForm.opCode.$dirty">#String.Format(Messages.cannotExceed, Labels.operatorCode, "6")</span>
</div>
</div>
</div>
</div>
The form itself is quite complex with several tabs.
I only see this problem in Chrome browser now, it works fine in IE (no question).
Although this does not answer your exact question, I do believe it will solve your problem. Consider doing your validation logic like this.
View
<div class="form-group" ng-class="{'has-error':!SomeForm.someValue.$valid && SomeForm.$submitted}">
<label class="control-label" for="someValue">Some Value</label>
<input id="someValue"
name="someValue"
class="form-control"
type="text"
placeholder="(Required)"
required
ng-model="vm.temp.someValue"
ng-maxlength="255"/>
<div class="help-block"
ng-messages="SomeForm.someValue.$error"
ng-if="SomeForm.$submitted">
<div ng-messages-include="ui/messages.tpl.html"></div>
</div>
</div>
Controller
vm.submit = function(Form, data) {
if (!Form || Form.$invalid) { return; }
if (vm.isUnchanged()) { return; }
someService.save(data).then(function () {
Form.$setPristine();
});
};
Below form is for modal window I have two fields if i select the values and without saving or even after save if i open modal window again i see all the required field messages, How can i reset the validation messages every time i open the modal window ?
main.html
<form name="addChallengeForm" id="addChallengeForm" novalidate ng-controller="challengesCtrl" class="border-box-sizing">
<div class="modalForm">
<div class="row">
<div class="form-group col-md-12 fieldHeight">
<label for="originatingGroup" class="required col-md-4">Originating group:</label>
<div class="col-md-8">
<select
kendo-drop-down-list
data-text-field="'text'"
data-value-field="'id'" name="originatingGroup"
k-option-label="'Select'" ng-model-options="{updateOn: 'blur'}"
ng-model="challengesDTO.originatingGrpLkupCode"
k-data-source="challengeGroupOptions"
id="originatingGroup" required>
</select>
<p class="text-danger" ng-show="addChallengeForm.originatingGroup.$touched && addChallengeForm.originatingGroup.$error.required">Originating group is required</p>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label for="challangeDes" class="required col-md-4">Description of challenge:</label>
<div class="col-md-8">
<textarea rows="4" class="form-control"
name="challangeDes" id="challangeDes"
ng-model="challengesDTO.challengeDescription" required
placeholder="Description of challenge" ng-model-options="{updateOn: 'blur'}">
</textarea>
<p class="text-danger" ng-show="addChallengeForm.challangeDes.$touched && addChallengeForm.challangeDes.$error.required">Description of challenge is required</p>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary pull-right" ng-disabled="addChallengeForm.$invalid" ng-click="submit()">Save</button>
</div>
</form>
mainCtrl.js
$scope.addChallenge = function (opCheckList,checklistSessionKey) {
challengesGridConfig.challengemodalWinConfig.title = 'Add challenge';
$scope.viewChallengeWin.setOptions(challengesGridConfig.challengemodalWinConfig);
$scope.$broadcast('addChallenge', $scope.riskAssessmentDTO.riskAssessmentKey,opCheckList,checklistSessionKey);
};
childCtrl.js
$scope.$on('addChallenge', function (s,id,opCheckList,checklistSessionKey){
$scope.viewChallengeWin.open().center();
$scope.editMode = false;
$scope.clearFields = clearForm();
});
var clearForm = function(){
$scope.challengesDTO = {
themesKyList: null
};
$scope.challengeGroupOptions = kendoCustomDataSource.getDropDownDataSource('RA_ASES_CHLNG_GRP');
$scope.challengThemesDataSource = kendoCustomDataSource.getDropDownDataSource('RA_CHLNG_THEME');
$scope.challengOutComeOptions = kendoCustomDataSource.getDropDownDataSource('RA_CHLNG_OUTCOME');
};
I think, when you are opening the modal you should reset conditions you're using in ng-show (for errors) to default. You're checking if input was touched, why don't you set it untouched when opening modal?
$scope.addChallengeForm.originatingGroup.$setUntouched();
$scope.addChallengeForm.challangeDes.$setUntouched();