"Michele Cella" <[EMAIL PROTECTED]> writes:
> That's exactly the reason I've added this, you can for example use a
> repeating widget and add new rows by just adding content to this id by
> using the fragment provided by a method like this:
>
> @expose(fragment=True)
> def method(self, repetition):
> return form.render_field_for("field", [repetition])
Hmmm... Today I added something like that and I suffered a lot with the
"fragment" idea (there's no test for it in Kid's tests, no examples I could
find on the web, etc.). Would you mind elaborating a little on this part for
the repeating widget?
What I did:
================================================================================
(in my controller)
@turbogears.expose(fragment = True, html =
'marketwatch.templates.form_compras_body')
def new_produto(self):
return dict(formulario_body = formulario_compras_body, data = dict(one
= True))
#oops! data is here just for testing ;-)
(in my template)
<div py:strip="True" xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://purl.org/kid/ns#">
<form>
<span py:replace="formulario_body.display(value = data)" />
<input id='btn_gravar' onclick="save_compras(this.form)" type="button"
value="Gravar" />
</form>
<div id="next_compra"></div>
</div>
(in my JavaScript)
function get_html_compras() {
var req = getXMLHttpRequest();
req.open("GET", '/compras/novo_produto/', true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var d = sendXMLHttpRequest(req);
return d.addCallback(add_produto);
}
function add_produto(data) {
var pdata = data.responseText;
var local = $('next_compra');
local.innerHTML = pdata;
}
(and there's a JavaScript function that manipulates the existing form, saving
its contents to the database, etc. and calling the above functions named
'save_compras')
(my form looks like this)
class fields_compras_body(widgets.WidgetsList):
compra_id = widgets.HiddenField(
validator = validators.Int(if_empty = None))
genero_id = widgets.SingleSelectField(
label = _(u'Gênero'),
css_classes = ['required'],
validator = validators.Int(not_empty = True),
options = generos,
)
produto = widgets.AutoCompleteField(
search_controller="/compras/search_produtos",
search_param="produto",
result_name="produtos",
text_field = widgets.TextField(attrs = {'size':51},
name = "text",
label = _(u'Produto'),
css_classes = ['required'],
validator =
validators.UnicodeString(not_empty = True),
),
)
quantidade = widgets.TextField(
attrs = {'size':'21', 'maxlength':'20'},
label = _(u'Quantidade'),
css_classes = ['required'],
validator = validators.Number(not_empty = True),
)
preco_unitario = widgets.TextField(
attrs = {'size':'21', 'maxlength':'20'},
label = _(u'Preço unitário'),
css_classes = ['required'],
validator = validators.Number(not_empty = True),
)
gasto_com_produto = widgets.Label(
label = _(u'Gasto com esse produto'),
)
formulario_compras_body = TableList(fields = fields_compras_body())
================================================================================
(TableList is like TableForm, but without the form part and the submit button.)
I have just made it work, and it is showing the new 'forms' and adding them in
the correct order, but it looks like my AutoCompleteFields aren't working for
the newly added forms.
Since I'm new to this "fragment" thing, I'd appreciate some help :-)
TIA,
--
Jorge Godoy <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears-trunk
-~----------~----~----~----~------~----~------~--~---