Spiral
1 week ago

How can update jquery append data on edit page

Posted 1 week ago by Spiral

Plz give me the best solution i have not concept and not finding the concept from last 2 days

i have a one form which including in create,edit file and in which some fields which appending with the help to jquery

appending successfully but are not update corrently when update or add multiple fields then again edit show only one input field

this is my code sample of edit page

controller

public function edit($id)
    {
        $projects       = Project::get();
        $collections    = Collection::get();
        $request        = RequestUrl::query()->findOrFail($id);
        $params         = Param::where('request_id', $request->id)->get();        
        return view('admin.requests.edit', compact('request', 'projects', 'collections', 'params'));                    
    }

edit.blade.php

			<div class="row">
	                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">                   
	                  	@include('admin.requests.partials._form', [
		                    'url' => route('admin.request.update', $request),
		                    'request' => $request,
		                    'params' => $params,
		                    'edit' 	  => true,
		                ])
	                </div> 
	              </div> 

@section('javascript')
	<script type="text/javascript">
   		$(document).ready(function(){

   			var i = 0;
		       
		    $("#addParams").click(function(){		   
		        ++i;	   
	        	$('#params').append('<div class="row"><div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"><div class="form-group"><input type="text" name="params['+i+'][key]" class="form-control" placeholder="Key"></div></div><div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"><div class="form-group"><input type="text" name="params['+i+'][value]" class="form-control" placeholder="Value"></div></div><a  id="remove" name="remove" class="action-icon  fa fa-minus-circle" style="margin-top: 10px;"></a></div></div>');		        
		    });	    	
		});	  	   
	</script>
@stop

form.blade.php

<div class="tab-pane fade in active" id="params" role="tabpanel" aria-labelledby="params-tab">
					<div>
						<a href="#addParams" id="addParams" name="add" class="action-icon  fa fa-plus-circle" aria-selected="false" style="margin-left: 16px;"></a>
					</div>
					@isset($edit) 
						@if($request->params)	
							@foreach($request->params as $param)							
							<div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
								<div class="form-group">
									<input type="text" name="params['+i+'][key]" class="form-control" placeholder="Key" value="{{ $param->key }}">
								</div>
							</div>
							<div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
								<div class="form-group">
									<input type="text" name="params['+i+'][value]" class="form-control" placeholder="Value" value="{{ $param->value }}">
								</div>
							</div>
							@endforeach
						@endif
					@endisset
				</div>

Please sign in or create an account to participate in this conversation.