I've created a form view in the website for the portal user. I'm fetching the datas from a model A.
What I'm trying to do here is, a user can see the already fetched data using (t-field in span) and the user needs to edit and save the resulting data needs to updated to the corresponding model. However when there is data fetched in the span field ,user can't edit the field and save
$('#edit_save').click(function(e) {
e.preventDefault();
editable = !editable;
if (editable) {
$(this).text('Save');
} else {
}
);
alert("Hello! I am an alert box!!"); $(this).text('Edit');
}
$('.input').each(function() {
var that = $(this);
if (editable) {
that.addClass('hidden');
$('<input value="' + that.text() + '">').insertAfter(that);
} else {
var input = that.next();
that.removeClass('hidden');
that.text(input.val());
input.remove();
}
})
})
.input {
margin: 5px;
position: relative;
}
<form class="form-horizontal" style="bg-light">
<t t-set="card_body">
<t t-foreach="health_record" t-as="hr">
#health_record = request.env['model'].search([)]
<div class="form-group">
<t>
<button id="edit_save" class="btn btn-primary">Edit</button>
<button id="health_profile" type="submit" class="btn btn-primary">Health Profile</button>
</t>
<h3 style="padding-top: 30px; padding-bottom: 45px; text-align: center; font-family: 'sans-serif'; font-weight: bold;" class="text-secondary">HEALTH RECORD</h3>
<div style="padding-bottom:1px;" class="col-md text-md-left">
<label class="text-secondary"><strong>Name:</strong></label>
<span t-field="hr.partner_id" class="input" title="Name" />
</div>
<div class="col-md text-md-left">
<label class="text-secondary"><strong >Age:</strong></label>
<span id="age" t-field="hr.age" class="input" title="Age" />
</div>
</t>
</t>
</form>