Dnia środa, 4 października 2006 05:06, Hari Krishna Dara napisał:
> A new version is available, to try:
>
> - Download the below file and put it in your autoload directory:
> http://haridara.googlepages.com/forms.vim
>
> - Start a fresh Vim session and execute:
> :call forms#demo()
>
> The new version has support for listening to changes in the field
> values. The demo can now automatically lookup city and state when you
> fill in your zipcode using a webservice (you need wget in the path and
> need Internet connection).

Using this version I wrote example tag form generated from xml data
file. It uses simple validation (only two fields: accesskey and dir)
acting when leaving field.
Playing with it gave me some more ideas:

- obligatory fields (and highlighting of that)
- single hotkey per form is real problem (try <C-G>o), at least shortcut
  should take to *first* field with that letter not last
- bug when first field is empty; cursor is placed directly after ':' in
  label, only Tab is taking it to real field; below workaround is
  putting always ' ' as value if field is empty.

How to use.

- open it ;)
- correct path to xml/xhtml10s.vim
- so %

-------------------------------------------------
" Form
" Data about attributes:
" g:xmldata_{b:html_omni_flavor}[tagname][1]


if !exists('g:xmldata_xhtml10s')
        source ~/.vim/autoload/xml/xhtml10s.vim
endif
let attrs = g:xmldata_xhtml10s['a'][1]
let g:tfList = {}
function! g:tfList.actionPerformed(name)
  if a:name ==# 'ok'
    let output = 
          \ "Output:\n"
    for i in g:formfields
                if b:curForm.getFieldValue(i) !~ '^\s*$'
                        let output .= i.'="'.b:curForm.getFieldValue(i)."\"\n"
                endif
        endfor
    call input(output)
    redraw
  else
    call input('Form cancelled, closing window')
    return ":bw!\<CR>"
  endif
endfunction
function! g:tfList.valueChanged(name, oldval, newval)
  if a:name == 'accesskey'
          function! UpdateAcckey()
                  if len(b:curForm.getFieldValue('accesskey')) > 1
                         call b:curForm.fieldMap['accesskey'].setValue(' ')
                 endif
          endfunction
          return ":call UpdateAcckey()\<CR>"
  elseif a:name == 'dir'
          function! UpdateDir()
                  if b:curForm.getFieldValue('dir') !~ '^\(\s*\|ltr\|rtl\)$'
                         call b:curForm.fieldMap['dir'].setValue('   ')
                 endif
          endfunction
          return ":call UpdateDir()\<CR>"
  endif
  return ''
endfunction
let htmlform = g:forms#form.new("Tag a")
let g:formfields = []
for attr in sort(keys(attrs))
        if len(attrs[attr]) == 0
          call htmlform.addTextField(attr, attr.':', ' ', attr[0])
    else
      call htmlform.addComboBox(attr, attr.':', '    ', attrs[attr], 
attr[0], 1)
    endif
        let g:formfields += [attr]
endfor
call htmlform.addButton('ok', 'OK', '', 'o', g:tfList)
call htmlform.addButton('cancel', 'cancel', '', 'c', g:tfList)
call htmlform.setDefaultButton('ok')
for field in htmlform.fields
  if field.type != g:forms#FT_BUTTON
        call field.setListener(g:tfList)
  endif
endfor
vert new
exe "normal! 30\<C-W>|"
call forms#ShowForm(htmlform)
-------------------------------------------------

Reply via email to