NMY Posted January 23, 2018 Report Share Posted January 23, 2018 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 ) Quote Link to comment Share on other sites More sharing options...
Zefirs Posted January 23, 2018 Report Share Posted January 23, 2018 Varbūt <input name= "form[processes][1][name]" ... Pārējiem laukiem pēc līdzības form[processes][1][qty] , form[processes][1][unit] ? Quote Link to comment Share on other sites More sharing options...
NMY Posted January 23, 2018 Author Report Share Posted January 23, 2018 [+] 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... Quote Link to comment Share on other sites More sharing options...
Kemito Posted January 24, 2018 Report Share Posted January 24, 2018 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. Quote Link to comment Share on other sites More sharing options...
NMY Posted January 24, 2018 Author Report Share Posted January 24, 2018 (edited) 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 January 24, 2018 by NMY Quote Link to comment Share on other sites More sharing options...
Zefirs Posted January 24, 2018 Report Share Posted January 24, 2018 Vari neupdeitot, un backend pusē iterē pāri ignorējot kāds ir index. Pievienojot jaunu lauku,paskaties kāds ir pēdējais index un palielini pa +1 jaunajam vai arī vispār vari random unikālus indeksus ģenerēt. Risinājumi var būt dažādi. Quote Link to comment Share on other sites More sharing options...
NMY Posted January 24, 2018 Author Report Share Posted January 24, 2018 ok I will check Quote Link to comment Share on other sites More sharing options...
Kemito Posted January 24, 2018 Report Share Posted January 24, 2018 This case, VueJS jau Tev palīdzētu izdarīt daudz lietu, un sen jau būtu beidzis čakarēties. Quote Link to comment Share on other sites More sharing options...
coofen Posted January 29, 2018 Report Share Posted January 29, 2018 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); }); }); Quote Link to comment Share on other sites More sharing options...
ViktorsN Posted January 30, 2018 Report Share Posted January 30, 2018 On 2018.01.24. at 3:09 PM, Kemito said: This case, VueJS jau Tev palīdzētu izdarīt daudz lietu, un sen jau būtu beidzis čakarēties. +1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.