1

How can I deserialize form if before I did so deserialize with jQuery? But now I use vue 3 and I need to deserialize with JSON.parse.

I store all data in Postgres and I need to deserialize with old name input.

var form_generate_page = "left_margin=1&right_margin=1&up_margin=1&bot_margin=1.7&secondColumnMarginTop=0&firstColumnMarginTop=0&marginMiddle=5&firstColumnMarginRight=5&DistanceBetweenLine=10.03176&mirror_margin=on&adding_space=on&different_marginTop=0&different_marginTopEven=5.5&different_marginTopOdd=5.7&different_marginLeft=0&different_marginLeftEven=0&different_marginLeftOdd=0";
                $("#form-generate-page").deserialize(form_generate_page);

I use different name input and name object

<input name="left_margin" v-model="object.left"/>

Script:

data () {
return{
    localMainPdf:{
        leftMargin:2,
        rightMargin:2,
        topMargin:2,
        bottomMargin:2,
    }
}
} 

clickTestSetProps() {
// data from DB
      var form_generate_page = "left_margin=1&right_margin=1&up_margin=1&bot_margin=1.7&secondColumnMarginTop=0&firstColumnMarginTop=0&marginMiddle=5&firstColumnMarginRight=5&DistanceBetweenLine=10.03176&mirror_margin=on&adding_space=on&different_marginTop=0&different_marginTopEven=5.5&different_marginTopOdd=5.7&different_marginLeft=0&different_marginLeftEven=0&different_marginLeftOdd=0";
    $("#form-generate-page").deserialize(form_generate_page);
    
    
                },

Template:

<form id ="form-generate-page">
<input  name = "left_margin" type="number" v-model="localMainPdf.leftMargin" step="any"  >
 <input  name = "right_margin" type="number" v-model="localMainPdf.rightMargin" step="any" >
 <input  name = "up_margin" type="number" v-model="localMainPdf.topMargin" step="any" >
 <input  name = "bot_margin" type="number" v-model="localMainPdf.bottomMargin" step="any" >
</form>

If I do this:

$("#form-generate-page").deserialize(form_generate_page);

data in mainPdf doesn't change

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
mobiw
  • 89
  • 7
  • Your string is in the same form as URL parameters, so I did a search. Does this answer your question? [How to convert URL parameters to a JavaScript object?](https://stackoverflow.com/questions/8648892/how-to-convert-url-parameters-to-a-javascript-object). It should work the same for your use case – yoduh Sep 11 '22 at 16:47
  • I use different name input and name object – mobiw Sep 11 '22 at 19:30
  • I'm not clear on what exactly you're trying to do. Can you explain the end goal, what your component's data looks like and/or what data you're receiving and what the final result should be? – yoduh Sep 11 '22 at 20:41
  • I think you mean to use `localMainPdf.leftMargin` as the v-model. ``. this will two-way bind the input value to that data property. – yoduh Sep 12 '22 at 15:13
  • @yoduh i get data from DB In this format "left_margin=1&right_margin=1&" and I need to send this data to model – mobiw Sep 13 '22 at 18:19

0 Answers0