Mam taki problem jak za pomocą ajax zresetować formularz
I tutaj wysyłam pola do skryptu PHP i są też do zaznaczenia pola i moge je odznaczać jak np. te id}}">{{$list->name}}
<form method='get' id="form2">
<table class='table table-bordered'>
<tr>
<td rowspan='2' style='padding-top: 35px; ' class='value'>
Godzina zaczęcia
</td>
<td class='borderless'>
<input type='date' name='dateStart' class='form-control' value='{{ date("Y-m-d")}}'>
</td>
</tr>
<tr>
<td class='borderless'>
<input type='time' name='timeStart' class='form-control'>
</td>
</tr>
<tr>
<td rowspan='2' style='padding-top: 35px; ' class='value'>
Godzina zakończenia
</td>
<td>
<input type='date' name='dateEnd' class='form-control' value='{{ date("Y-m-d")}}'>
</td>
</tr>
<tr>
<td>
<input type='time' name='timeEnd' class='form-control' onkeypress="addMood('{{ route('Mood.Add')}}')">
</td>
</tr>
<tr>
<td class='value'>
Poziom nastroju
</td>
<td>
<input type='text' name='moodLevel' class='form-control' onkeypress="addMood('{{ route('Mood.Add')}}')">
</td>
</tr>
<tr>
<td class='value'>
Poziom lęku
</td>
<td>
<input type='text' name='anxietyLevel' class='form-control' onkeypress="addMood('{{ route('Mood.Add')}}')">
</td>
</tr>
<tr>
<td class='value'>
Poziom napięcia
</td>
<td>
<input type='text' name='voltageLevel' class='form-control' onkeypress="addMood('{{ route('Mood.Add')}}')">
</td>
</tr>
<tr>
<td class='value'>
Poziom pobudzenia
</td>
<td>
<input type='text' name='stimulationLevel' class='form-control' onkeypress="addMood('{{ route('Mood.Add')}}')">
</td>
</tr>
<tr>
<td class='value'>
Ilośc epizodów psychotycznych
</td>
<td>
<input type='number' name='epizodesPsychotic' class='form-control' value='0' min='0' onkeypress="addMood('{{ route('Mood.Add')}}')">
</td>
</tr>
<tr>
<td class='value' style='padding-top: 30%; ' rowspan="2">
Co robiłem
</td>
<td>
<textarea name='whatWork' class='form-control' rows='7'></textarea>
</td>
</tr>
<tr>
<td>
<div style="overflow-y: scroll; height:250;">
@foreach ($Action as $list)
<a class="Action___" id = "{{$list->id}}">{{$list->name}}</a> |
@endforeach
</div>
</td>
</tr>
<tr>
<td colspan="2" class="center">
<input type="button" onclick="addMood('{{ route('Mood.Add')}}')" class="btn btn-success" value="Dodaj nastrój" >
</td>
</tr>
<tr>
<td colspan="2" class="center">
<div class="ajax" id="form"></div>
</td>
</tr>
</table>
</form>
var actionList = [];
$(document).ready(function(){
$(".Action___").click(function(){
if (getNumber($(this).attr("id"),actionList)) {
actionList.remove($(this).attr("id"));
$(this).css("background-color","transparent");
$(this).css("border-radius",'0px');
$(this).css("color","#4288BA");
}
else {
actionList.push($(this).attr("id"));
$(this).css("background-color","#95721F");
$(this).css("border-radius",'30px');
$(this).css("color","white");
}
//alert(actionList.length);
});
});
Array.prototype.remove=function(s){
for(i=0;i<s.length;i++){
if(s==this[i]) this.splice(i, 1);
}
}
const getNumber = function ( num, arr ) {
return arr.includes( num );
}
function addMood(url) {
changeArrayAtHidden();
//alert($("form").serialize());
//deleteArray();
//$('form')[0].reset();
//$('#form2')[0].reset();
$("#form").load(url + "?" + $("form").serialize());
//alert("dd");
}
function changeArrayAtHidden() {
for (i=0;i < actionList.length;i++) {
if (isIst(actionList[i])) {
$("form").append("<input type=\'hidden\' name=\'idAction[]\' value=" + actionList[i] + " class=\'form-control typeMood\'>");
}
}
}
function isIst(id) {
if (actionList.length == 0) {
return false;
}
for (i=0;i < actionList.length;i++) {
if (actionList[i] == id) {
return true;
}
}
return false;
}
function deleteArray() {
for (i=0;i < actionList.length;i++) {
actionList.splice(i, 1);
}
}
No i teraz chodzi o to, że w momencie kiedy jest akacja wyślij fomrularz to pamięta niektóre pola i ich nie resetuje nawet ja je odznacze