milfont / jsonform Goto Github PK
View Code? Open in Web Editor NEWCreate standard JSON from Forms or populate form with json using jQuery
Home Page: http://www.milfont.org/
Create standard JSON from Forms or populate form with json using jQuery
Home Page: http://www.milfont.org/
O erro está ao efetivar merge entre o json intermediario (cada item do array) com o json principal (o retornado)
Segundo MDN: https://developer.mozilla.org/En/HTML/Element/Input#attr-type
"A check box. You must use the value attribute to define the value submitted by this item. Use the checked attribute to indicate whether this item is selected. You can also use the indeterminate attribute to indicate that the checkbox is in an indeterminate state (on most platforms, this draws a horizontal line across the checkbox)."
Considerando que json retornado pelo método getJSON pode ser submetido a um serviço http, ele deve representar, de forma identica, o formulário ou inputs em questão.
Converting types of values like that:
var byId = true,
config = {
numeric: ["value"],
date: ["date"]
}
var json = jQuery("#myform").getJSON(byId, config);
typeof json.value === "number"
Object.prototype.toString.call(json.date) === "[object Date]"
Coverage checkbox
JsonForm está conflitando com a biblioteca do Jquery-ui.
Json:
{"transacao": {"id": 240,"data": "01/08/13","valor": "111.11","fluxo": "ENTRADA","descricao": "fsdfd","conta": {"id": 2},"tags": [{"id": 1},{"id": 2}]}}
Chamada ao jsonform:
$("#form_transacao").populate(data); // data from json
Atente para a seguinte linha:
https://github.com/milfont/jsonform/blob/master/lib/jsonform.js#L142
Na primeira execução do loop, o debug mostra:
$("form#form_transacao.form-horizontal").find("[name='transacao\.tags\[\]\.id']").eq(0)
other.val(value);
E o elemento (select-multiple) é encontrado corretamente.
Mas, na segunda execução do loop, o debug mostra:
$("form#form_transacao.form-horizontal").find("[name='transacao\.tags\[\]\.id']").eq(1)
other.val(value);
Não encontra o elemento.
Não sei por que foi utilizado o .eq(index) na linha:
https://github.com/milfont/jsonform/blob/master/lib/jsonform.js#L145
Mesmo que o elemento fosse encontrado o valor do select-multiple seria substituído, não adicionado de mais um 'option' com 'selected'.
A forma correta de se atribuír um valor a um select-multiple com jquery, não seria?
$(selector).val([1,2,3])
Se executar for como abaixo, e como parece ser o comportamento do jsonform, o comportamento não seria o mesmo:
$(selector).val(1)
$(selector).val(2)
$(selector).val(3)
When you have the value = 0(zero) coming from the json, the populate does not fill the referenced input with any value, it just leaves it blank, it should bring it as 0(zero)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.