Does redux-form change prop argument value as function work? - redux-form

I have "redux-form": "^7.4.2".
I see in the docs:
change(field:String, value:any) : Function Changes the value of a
field in the Redux store. This is a bound action creator, so it
returns nothing. You could get current field-value & form-values while
value is a function, For example: change(field, (fieldValue,
allValues) => {})
I try to do:
dispatch(
change(formName, fieldName, (val, allValues) => {
/* do something with arguments */
return theResultOfTheAboveCode;
}),
);
It does not work. But the below code works fine:
dispatch(change(formName, fieldName, someValue));
Does the function as the value work?

You are using 7.4.2 which does not have the value as function.
The docs are under https://redux-form.com/7.4.2/docs/api/props.md/
The value as a function exists on the newest 8.x.x https://redux-form.com/8.1.0/docs/api/props.md/

Related

Unable to return function value from custom command

I am having a hard time returning a value from a custom command function to the main file.
command.js
spec.js
it does not return the expected value
Do you want to return the decodedTotp value?
If yes, you have to do this explicitly at the end of your custom function:
<...>
console.log(decodedTotp)
return decodedTotp
})
})

How to past value from get method into custom method

I am finding the way how to get value from get method into custom command.
Code shoud look like this:
cy.get('#alias').customCommand(name)
I know i can send it throw parameter like cy.customCommand('#alias', name), but i would like to use chain and in customCommand get value from previous chained command.
Is it posible?
I figured out. Look at https://code.i-harness.com/en/docs/cypress/api/cypress-api/custom-commands
by this, you have to add into your custom command option {prevSubject: true} and then method get will past value into first parameter of your custom command.
So:
support/commands.ts
Cypress.Commands.add('customCommand', { prevSubject: true }, (element, datatable, jqSelection) => {..})
support/index.ts
declare global {
namespace Cypress {
interface Chainable {
customCommand(datatable, jqSelection): void
}
}
}
Your step:
cy.get('#value').customCommand(datatable, jqselection)
You can do something like this:
cy.get('#alias').then((name) => {
cy.customCommand(name)
})

Backpack V4 modifying field before store

In 3.6 version of backpack I can change an attribute value before storing it.
I have this code
If ($request->description == "") {
$request->description="User has not entered any description";
}
$redirect_location = parent::storeCrud($request);
What can I do to get the same in V4? I'm reading this guide but I can't make it to work.
This is what I'm trying in V4
public function store(PedidoRequest $request)
{
Log::debug('testing...');
If ($request->description == "") {
$request->description="User has not entered any description";
}
$redirect_location = $this->traitStore();
return $redirect_location;
}
The Request object in Laravel, Illuminate\Http\Request, doesn't have the ability to set the inputs via the properties like that, no __set method ($request->description = '...' does not set an input named description). You would have to merge the inputs into the request or use the array syntax to do that:
$request->merge(['description' => '...']);
// or
$request['description'] = '...';
But since backpack seems to have abstracted things apparently you aren't controlling anything in your controller methods you could try this:
$this->crud->request->request->add(['description'=> '...']);
Potentially:
$this->request->merge(['description' => '...']);
That would be assuming some trait the Controller uses is using the Fields trait.

Redux-form: input value is not yet set onChange of input

When the user picks a value from a select dropdown, the onChange calls a function in the parent container. There I need to check which fields are filled.
But it appears that the value hasn't been set in the form yet.
I have tried to use the selectors valid and getFormvalues, but they are not updated with the latest form value change.
See this codesandbox.
If I print getFormvalues in the render of the form component, it is updated, but I can't handle the form there.
So how can I handle the form after the user picks a value, where the form is updated?
You are already receiving values in the SimpleFormContainer due to connect. You don't need the callback from SimpleFormContainer to SimpleForm. You can use the componentWillReceiveProps in the SimpleFormContainer to check the values update and do whatever you want.
The final code might look like:-
class SimpleFormContainer extends React.Component {
componentWillReceiveProps(nextValues) {
if (this.props.formValues !== nextValues.formValues){
console.log(nextValues.formValues)
}
}
render() {
return (
<SimpleForm onSubmit={showResults}/>
)
}
}
SimpleFormContainer = connect(
state => ({
formValues: getFormValues('simple')(state)
}),
{ getFormValues }
)(SimpleFormContainer);
Working example

Joomla JInput default value

If I grab a value from my form in my controller using:
$jinput = JFactory::getApplication()->input;
$add_name = $jinput->get('name', 'Default name', 'STRING');
I expect the default value to be set as a string called Default name.
But if I test this it doesn't seem to think there is a value:
if (!empty($add_name))
{
//do stuff
//I expect to be here because $add_name="Default name"
}
else
{
//I actually go here
}
Am I misunderstanding the default value?
EDIT
If a form is submitted with an empty string then that is what will be returned. I understand that (now). But under what circumstance will the default value Default name ever get assigned to $add_name
If you submitted an empty string in your form, then it's used instead of the default value. JInput does isset() check, not empty(), so empty string is considered as a valid value.

Resources