Commit a15aec35 authored by Holger Weiss's avatar Holger Weiss Committed by JC Brand

Assume "text-single" as default form field type

As per XEP-0004, the default "type" of data form fields is
"text-single", so a missing "type" attribute should not be treated
differently.

This fixes handling of CAPTCHAs offered by ejabberd.
parent 37800d92
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
- Upgrade to Backbone 1.4.0 - Upgrade to Backbone 1.4.0
- Fix "flashing" of roster filter when you have less than 5 roster contacts. - Fix "flashing" of roster filter when you have less than 5 roster contacts.
- Fix handling of CAPTCHAs offered by ejabberd.
- Allow setting of debug mode via URL with `/#converse?debug=true` - Allow setting of debug mode via URL with `/#converse?debug=true`
- New config setting [locked_muc_domain](https://conversejs.org/docs/html/configuration.html#locked-muc-domain) - New config setting [locked_muc_domain](https://conversejs.org/docs/html/configuration.html#locked-muc-domain)
- New config setting [show_client_info](https://conversejs.org/docs/html/configuration.html#show-client-info) - New config setting [show_client_info](https://conversejs.org/docs/html/configuration.html#show-client-info)
......
This diff is collapsed.
...@@ -539,89 +539,85 @@ u.xForm2webForm = function (field, stanza, domain) { ...@@ -539,89 +539,85 @@ u.xForm2webForm = function (field, stanza, domain) {
* Parameters: * Parameters:
* (XMLElement) field - the field to convert * (XMLElement) field - the field to convert
*/ */
if (field.getAttribute('type')) { if (field.getAttribute('type') === 'list-single' ||
if (field.getAttribute('type') === 'list-single' || field.getAttribute('type') === 'list-multi') {
field.getAttribute('type') === 'list-multi') {
const values = _.map(
const values = _.map( u.queryChildren(field, 'value'),
u.queryChildren(field, 'value'), _.partial(_.get, _, 'textContent')
_.partial(_.get, _, 'textContent') );
); const options = _.map(
const options = _.map( u.queryChildren(field, 'option'),
u.queryChildren(field, 'option'), function (option) {
function (option) { const value = _.get(option.querySelector('value'), 'textContent');
const value = _.get(option.querySelector('value'), 'textContent'); return tpl_select_option({
return tpl_select_option({ 'value': value,
'value': value, 'label': option.getAttribute('label'),
'label': option.getAttribute('label'), 'selected': _.includes(values, value),
'selected': _.includes(values, value), 'required': !_.isNil(field.querySelector('required'))
'required': !_.isNil(field.querySelector('required')) })
}) }
} );
); return tpl_form_select({
return tpl_form_select({ 'id': u.getUniqueId(),
'id': u.getUniqueId(), 'name': field.getAttribute('var'),
'name': field.getAttribute('var'), 'label': field.getAttribute('label'),
'label': field.getAttribute('label'), 'options': options.join(''),
'options': options.join(''), 'multiple': (field.getAttribute('type') === 'list-multi'),
'multiple': (field.getAttribute('type') === 'list-multi'), 'required': !_.isNil(field.querySelector('required'))
'required': !_.isNil(field.querySelector('required')) });
}); } else if (field.getAttribute('type') === 'fixed') {
} else if (field.getAttribute('type') === 'fixed') { const text = _.get(field.querySelector('value'), 'textContent');
const text = _.get(field.querySelector('value'), 'textContent'); return '<p class="form-help">'+text+'</p>';
return '<p class="form-help">'+text+'</p>'; } else if (field.getAttribute('type') === 'jid-multi') {
} else if (field.getAttribute('type') === 'jid-multi') { return tpl_form_textarea({
return tpl_form_textarea({ 'name': field.getAttribute('var'),
'name': field.getAttribute('var'), 'label': field.getAttribute('label') || '',
'label': field.getAttribute('label') || '', 'value': _.get(field.querySelector('value'), 'textContent'),
'value': _.get(field.querySelector('value'), 'textContent'), 'required': !_.isNil(field.querySelector('required'))
'required': !_.isNil(field.querySelector('required')) });
}); } else if (field.getAttribute('type') === 'boolean') {
} else if (field.getAttribute('type') === 'boolean') { return tpl_form_checkbox({
return tpl_form_checkbox({ 'id': u.getUniqueId(),
'id': u.getUniqueId(), 'name': field.getAttribute('var'),
'name': field.getAttribute('var'), 'label': field.getAttribute('label') || '',
'label': field.getAttribute('label') || '', 'checked': _.get(field.querySelector('value'), 'textContent') === "1" && 'checked="1"' || '',
'checked': _.get(field.querySelector('value'), 'textContent') === "1" && 'checked="1"' || '', 'required': !_.isNil(field.querySelector('required'))
'required': !_.isNil(field.querySelector('required')) });
}); } else if (field.getAttribute('var') === 'url') {
} else if (field.getAttribute('var') === 'url') { return tpl_form_url({
return tpl_form_url({ 'label': field.getAttribute('label') || '',
'label': field.getAttribute('label') || '', 'value': _.get(field.querySelector('value'), 'textContent')
'value': _.get(field.querySelector('value'), 'textContent') });
}); } else if (field.getAttribute('var') === 'username') {
} else if (field.getAttribute('var') === 'username') { return tpl_form_username({
return tpl_form_username({ 'domain': ' @'+domain,
'domain': ' @'+domain, 'name': field.getAttribute('var'),
'name': field.getAttribute('var'), 'type': XFORM_TYPE_MAP[field.getAttribute('type')],
'type': XFORM_TYPE_MAP[field.getAttribute('type')], 'label': field.getAttribute('label') || '',
'label': field.getAttribute('label') || '', 'value': _.get(field.querySelector('value'), 'textContent'),
'value': _.get(field.querySelector('value'), 'textContent'), 'required': !_.isNil(field.querySelector('required'))
'required': !_.isNil(field.querySelector('required')) });
}); } else if (field.getAttribute('var') === 'ocr') { // Captcha
} else { const uri = field.querySelector('uri');
return tpl_form_input({ const el = sizzle('data[cid="'+uri.textContent.replace(/^cid:/, '')+'"]', stanza)[0];
'id': u.getUniqueId(), return tpl_form_captcha({
'label': field.getAttribute('label') || '', 'label': field.getAttribute('label'),
'name': field.getAttribute('var'), 'name': field.getAttribute('var'),
'placeholder': null, 'data': _.get(el, 'textContent'),
'required': !_.isNil(field.querySelector('required')), 'type': uri.getAttribute('type'),
'type': XFORM_TYPE_MAP[field.getAttribute('type')], 'required': !_.isNil(field.querySelector('required'))
'value': _.get(field.querySelector('value'), 'textContent') });
});
}
} else { } else {
if (field.getAttribute('var') === 'ocr') { // Captcha return tpl_form_input({
const uri = field.querySelector('uri'); 'id': u.getUniqueId(),
const el = sizzle('data[cid="'+uri.textContent.replace(/^cid:/, '')+'"]', stanza)[0]; 'label': field.getAttribute('label') || '',
return tpl_form_captcha({ 'name': field.getAttribute('var'),
'label': field.getAttribute('label'), 'placeholder': null,
'name': field.getAttribute('var'), 'required': !_.isNil(field.querySelector('required')),
'data': _.get(el, 'textContent'), 'type': XFORM_TYPE_MAP[field.getAttribute('type')],
'type': uri.getAttribute('type'), 'value': _.get(field.querySelector('value'), 'textContent')
'required': !_.isNil(field.querySelector('required')) });
});
}
} }
} }
export default u; export default u;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment