Skip to content

Commit

Permalink
Merge pull request #802 from luisrudge/clear-fields-when-auth-is-succ…
Browse files Browse the repository at this point in the history
…essful

Clearing fields when lock closes
  • Loading branch information
glena authored Jan 16, 2017
2 parents 0a852c6 + d0e27b6 commit d5a1a06
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/core/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { syncRemoteData } from './remote_data';
import * as l from './index';
import { img as preload } from '../utils/preload_utils';
import { defaultProps } from '../ui/box/container';
import { isFieldValid, showInvalidField, hideInvalidFields } from '../field/index';
import { isFieldValid, showInvalidField, hideInvalidFields, clearFields } from '../field/index';

export function setupLock(id, clientID, domain, options, hookRunner, emitEventFn) {
let m = l.setup(id, clientID, domain, options, hookRunner, emitEventFn);
Expand Down Expand Up @@ -104,11 +104,12 @@ export function closeLock(id, force = false, callback = () => {}) {
// otherwise just reset.
if (l.ui.appendContainer(m)) {
swap(updateEntity, "lock", id, l.stopRendering);

setTimeout(() => {
swap(updateEntity, "lock", id, (m) => {
m = hideInvalidFields(m);
m = l.reset(m);
m = clearFields(m);
return m;
});
m = read(getEntity, "lock", id);
Expand All @@ -118,6 +119,7 @@ export function closeLock(id, force = false, callback = () => {}) {
swap(updateEntity, "lock", id, (m) => {
m = hideInvalidFields(m);
m = l.reset(m);
m = clearFields(m);
return m;
});
callback(m);
Expand Down
4 changes: 2 additions & 2 deletions src/field/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ export function clearFields(m, fields) {
let keyPaths;

if (!fields || fields.length === 0) {
keyPaths = ["field"];
keyPaths = [["field"]];
} else {
keyPaths = fields.map(x => ["field", x]);
}

return keyPaths.reduce((r, v) => r.removeIn(v), m);
}

Expand Down

0 comments on commit d5a1a06

Please sign in to comment.