Jump to content
php.lv forumi

Laravel Collective Forms - kā apstrādāt datus?


NMY

Recommended Posts

Esmu izveidojis šādu dinamisku formu, kurā pielikt/noņemt attiecīgi Procesi/Materiāli.

id un name lauki attiecīgi id="processes[]" name="processes[]" un id="materials[]" name="materials[]"

Tālāk gribas saņemt Kontrolierī kaut kā pārskatāmi to visu...

Vai tiešām būs jāraksta jquery un jābrien cauri visai formai, lai samapotu materials => daudzums laukus? Varbūt kādi ieteikumi?

$request->all() izdod sekojošo:

Array ( 
  [name] => Heavy Metal 
  [processes] => Array ( [0] => [1] => 2 [2] => 3 [3] => ) 
  [quantity] => Array ( [0] => [1] => [2] => 1.00000 [3] => 3.00000 [4] => [5] => 1.00000 [6] => 50.00000 [7] => ) 
  [materials] => Array ( [0] => [1] => 2 [2] => 3 [3] => ) 
  [_method] => PUT )

image.thumb.png.40b079b713d377c71d07d2e146a3d85d.png

Link to comment
Share on other sites

[+] Process un [+] Materiāls ir div bloks display: none, kuru es klonēju. Pārējos saražo blade template @foreach loopā. 

Attiecīgi neko vairāk par id="processes[]" name="processes[]" un id="materials[]" name="materials[]" izdomāt nevaru...

Atgriežos pie tā, ka iespējams jāizmanto vuejs, ko tik vienkārši pa 2h ierubīties nevarēšu...

Link to comment
Share on other sites

Tev taču Zefīrs jau parādīja ideju. Lieto indexu. Kaut vai sāc ar to, ka ģenerējot formu no PHP lieto indexu. 
process[1][name], process[2][name], materials[1][name], materials[2][name] and so on.
Kad tas ir, sapratīsi ka backend pusē jau ir skatāms risinājums. Tālāk izpīpē kā to visu sataisīt ar savu plusiņmīnusiņ sistēmu.

Link to comment
Share on other sites

process[0][name], process[0][quantity] [ - ]
process[1][name], process[1][quantity] [ - ]
process[2][name], process[2][quantity] [ - ]
[ + ] process[?][name], process[?][quantity] [ - ]
materials[0][name], materials[0][quantity] [ - ]
materials[1][name], materials[1][quantity] [ - ]
materials[2][name], materials[2][quantity] [ - ]
[ + ] materials[?][name], materials[?][quantity] [ - ]

var mēģināt ar jquery apdeitot indexu, bet no malas izskatās čerez (‿ˠ‿)

labojiet ja kļūdos

Edited by NMY
Link to comment
Share on other sites

Parasti šo risināju, ka indeksa vietā lieku kaut kādu placeholder

<input name="data[{{index}}][qty]" />

, un tad uz formas submit

onsubmit...
$('tr').each(function(row, index) {
	row.find('input').each(function(input) {
		input.attr('name', input.attr('name').replace('{{index}}', index);
	});
});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...