Mercurial > prosody-hg
comparison util/dataforms.lua @ 9125:da7a2db01d6a
Merge with jonasw
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 06 Aug 2018 08:21:55 +0100 |
| parents | e5eb36ee07a2 |
| children | 68694c1bd960 |
comparison
equal
deleted
inserted
replaced
| 9124:dcc490f0044d | 9125:da7a2db01d6a |
|---|---|
| 140 return form; | 140 return form; |
| 141 end | 141 end |
| 142 | 142 |
| 143 local field_readers = {}; | 143 local field_readers = {}; |
| 144 | 144 |
| 145 function form_t.data(layout, stanza) | 145 function form_t.data(layout, stanza, current) |
| 146 local data = {}; | 146 local data = {}; |
| 147 local errors = {}; | 147 local errors = {}; |
| 148 local present = {}; | 148 local present = {}; |
| 149 | 149 |
| 150 for _, field in ipairs(layout) do | 150 for _, field in ipairs(layout) do |
| 155 break; | 155 break; |
| 156 end | 156 end |
| 157 end | 157 end |
| 158 | 158 |
| 159 if not tag then | 159 if not tag then |
| 160 if field.required then | 160 if current and current[field.name] ~= nil then |
| 161 data[field.name] = current[field.name]; | |
| 162 elseif field.required then | |
| 161 errors[field.name] = "Required value missing"; | 163 errors[field.name] = "Required value missing"; |
| 162 end | 164 end |
| 163 elseif field.name then | 165 elseif field.name then |
| 164 present[field.name] = true; | 166 present[field.name] = true; |
| 165 local reader = field_readers[field.type]; | 167 local reader = field_readers[field.type]; |
