Note that there is an issue with show_if
https://groups.google.com/forum/#!topic/web2py/dnbPyALwZKE
On Friday, November 7, 2014 5:37:27 PM UTC-5, Jeremiah Peterson wrote:
>
> Thank you very much, I really appreciate it. That worked perfectly!
>
> On Friday, November 7, 2014 4:11:09 PM UTC-6, DenesL wrote:
>>
>> Hi Jeremiah,
>>
>> the show_if hides the whole row as it applies a display:none to it.
>> In the custom forms we can only access individual components, not the
>> whole row (AFAIK).
>>
>> But, you can get it work by including an element with the same id as the
>> row that is being hidden, e.g.
>>
>> <div id="news_link__row">Link: {{=form.custom.widget.link}}<br></div>
>>
>> Denes.
>>
>> On Thursday, November 6, 2014 8:56:10 PM UTC-5, Jeremiah Peterson wrote:
>>>
>>> My controller is this.
>>>
>>>
>>> def news_create():
>>> db.news.link.show_if = (db.news.category==1)
>>> db.news.votes.default = 0
>>> form = SQLFORM(db.news)
>>> return locals()
>>>
>>>
>>> And the view is this.... thanks so much for looking.
>>>
>>>
>>> {{extend 'layout.html'}}
>>>
>>> <h2>New Item</h2>
>>> {{=form.custom.begin}}
>>> Type: {{=form.custom.widget.category}}<br><br>
>>> Title: {{=form.custom.widget.title}}<br><br>
>>> Link: {{=form.custom.widget.link}}<br><br></div>
>>> Comment: {{=form.custom.widget.comment}}<br><br></div>
>>> {{=form.custom.submit}}
>>> {{=form.custom.end}}
>>>
>>>
>>> The html comes out like this.
>>>
>>> <foraction="#"enctype="multipart/formdatamethod="post">Type: <select
>>> class="generic-widget" id="news_category" name="category"><option value=
>>> </option><option value="2">ask</option><option value="1">share</option>
>>> </select><br><br>Title: <input class="string" id="news_title" name="
>>> title" type="text" value="" /><br><br>Link: <input class="string" id="
>>> news_link" name="link" type="text" value="" /><br><br></div>Comment:
>>> <textarea
>>> class="text" cols="40" id="news_comment" name="comment" rows="10">
>>> </textarea><br><br></div><input type="submit" value="Submit" /></form>
>>>
>>>
>>> I tried to wrap the Title line and Link line with some divs with ID's
>>> and then tried to show/hide them using javascript depending on what the
>>> drop down value was for category field. For some reason I wasn't able to
>>> make that work either. I could get it working in jsfiddle, but then when I
>>> put that js in my view it wouldn't work. I've never done any js coding
>>> before though so wasn't real confident on what I was doing.
>>>
>>> Basically what I'm trying to do is if the person chooses ask, they
>>> should see the comment input, and then if these choose share, they see the
>>> link input field.
>>>
>>> Jeremiah
>>>
>>>
>>> On Thursday, November 6, 2014 7:35:57 PM UTC-6, Massimo Di Pierro wrote:
>>>>
>>>> Can you show us your form? Do you use {{=form.custom.widget[field]}} or
>>>> <input..../>. The latter is not supposed to work
>>>>
>>>> On Thursday, 6 November 2014 09:45:10 UTC-6, Jeremiah Peterson wrote:
>>>>>
>>>>> in my controller I have
>>>>>
>>>>> db.news.link.show_if = (db.news.category==1)
>>>>>
>>>>> In my view if I just use {{=form}} then it will only show the 'link'
>>>>> field if the category field is set to 1.
>>>>>
>>>>> However if I use {{=form.custom.begin}} so can I can place my form
>>>>> fields in the order I want, it doesn't make that link field conditional
>>>>> any
>>>>> longer.
>>>>>
>>>>>
>>>>> Is there a way to fix this, or is there a way to use {[=form}} and
>>>>> have my fields show up in the order I want them too?
>>>>>
>>>>> Thanks,
>>>>> Jeremiah
>>>>>
>>>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.