Trying to use EJS to dynamically render an edit form - forms

The problem seems to be with EJS. I might be trying to do something EJS wasn't designed for.
I'm working on a web app that uses forms with a variable number of fields. If a Mongo document I'm editing has only one field, I don't want to display input boxes for any additional fields.
I'm able to dynamically control how many fields are displayed when documents are edited but I'm not able to dynamically display the current value of the fields.
If I use the value tag like this: value=<%= document.field1 %>, it works fine. This, however, would have to be manually repeated for each field, including fields that won't be present.
What I want to do is something like this: value=<%= 'document.field' + (i+1) %>. This would ideally produce the same rendered HTML the code above does. However, what I see is 'document.field1' rather than the data I want to retrieve from the database.

EJS is just a thin wrapper around JavaScript code. Anything you can write in JavaScript you can write in EJS, it'll be included in the compiled template without modification.
So to reference a field with a dynamic name you'd use [] just like you would in any other JavaScript code. Based on the code you provided it would be something like this:
value="<%= document['field' + (i + 1)] %>"

Related

redux-form Wizard form with linked fields

I am building a multi-step application form with React. Having first built it with pure internal state I am now in the process of refactoring to Redux using redux-form.
Having used the example here as a basis: http://redux-form.com/5.2.5/#/examples/wizard?_k=oftw7a we have come a good way.
However the problem appears when i have two forms which are supposed to have the same value. During one of the pages i have a name field, that is supposed to be duplicated on the name field of the next page. The opposite should happen if you go back from the last page. Any tips to how this could be achieved?
Using the wizard, you are basically working with the exact same form that's split into multiple pieces. Ultimately it's the same form, because redux-form tracks them by name. It is how the library identifies the pieces of the same form - using the name.
form: 'wizard',
Here you can see that the exact same instance of the form will be shared throughout the pieces. fields work in a similar manner. Each field is defined as part of a form.
As long as you use the same field constants inside the fields object that you pass into the reduxForm function and as long as the value for form is the same, so that they use the same underlying form object, it should work for you just fine.
On one page you should pass in
export default reduxForm({
form: 'wizard',
fields : {
'fieldIWantOnBothPartsOfTheForm',
'someOtherFieldThatShouldOnlyBeHere',
},
...
And then on the other page:
export default reduxForm({
form: 'wizard',
fields : {
'fieldIWantOnBothPartsOfTheForm',
'thirdFieldHere',
},
...
Also, make sure you keep destroyOnUnmount equal to false if you want to navigate back-and-forth.
Hope that helps.

Auto populate form input based on name?

If I have a Command Object such as
class AppContactInfoCommand {
String fname = "Tom";
}
When I pass that command object to my view to populate my form I have to do this
<g:textField name="cmd.fname" value="${cmd.fname}"/>
This just seems extremely repetitive and time consuming if I have large forms with many fields. Isn't there any way to to have the g:textField intelligently detect that value and auto-populate the value field so all I have to do is
<g:textField name="cmd.fname" />
Other frameworks I have worked with do this so Im sure there must be a way from Grails to do this too.
Grails Version: 3.1
There is nothing stopping you from writing your own tag library to do just that. However the included tag libraries for such things as the textField do not have this behavior. As can be seen from the documentation.

repopulate form data from an existing document

I am trying to repopulate fields on a HTML form with a users data they initially filled out when they created an account for the first time in Meteor to allow them to edit information. The form contains various inputs, option lists and check boxes. The data stores on in the collection with no issues. I have a field in the user profile called profComp which is either true of false dependent on if the form has been filled out before. I have tried to add an if/else statement on the route -
Router.route("/edit_dashboard", function(){
if(Meteor.user().profile.profComp)
{
this.render("change_edit_dashboard");
}
else
{
this.render('edit_dashboard');
}
The change_edit_dashboard is a copy of the html form the user initially filled out and I have added a helper to the change_edit_dashboard template to retrieve the users info document from the collection.
Template.change_edit_dashboard.helpers({
formData: function()
{
return Base.findOne({_id: Session.get('baseId')})
}
});
And attempted to call context of document using spacebars {{#with}} in change_edit_dashboard
<template name="change_edit_dashboard">
{{#with formData}}
----> form code <------
{{/with}}
</template>
However a few strange things seem to be happening -
The change_edit_dahsboard template is not rendering at all. The formData helper doesn't seem to be getting called as I am not getting a test console.log() I wrote showing in the console.
With the addition of this code it seems to breaking all functionality of other templates. I have placed test console.log() in various template events and they do not seem to be getting called
Can anyone advise on where I may be going wrong? Thanks
As you did not give us your form code, I'll just assume you correctly gave <input name="myInput" value=myValueHelper> attributes to your inputs and go on.
From what I see, you are trying to get data from one of the most error-prone objects in Meteor, Meteor.users when one wants to retrieve data from a collection object. You can find below some possibilities regarding your issue:
Meteor.user().profile.profComp does not exist. As you are manipulating Meteor.users collection, you have to take a few extra-step in order to access data stored there. For example, if I have a mySuperField field at the root of my Meteor.users model, I have to publish it server-side in order to subscribe and retrieve it on the client. You can quickly check it by calling Meteor.user() and see wether it's present or not.
If you have a blank screen with no error server-side, it's often because you broke your templating load. Check error messages at the top of your web-console and make sure you did not put a template helper in a file executed on the server or before your .html file was loaded by Meteor.
I'm not exactly sure why you need 2 edit templates but if it's just a matter of new vs edit, you should consider using autoform with simple-schema as it will greatly help you through your forms. You can find the links below.
https://github.com/aldeed/meteor-simple-schema
https://github.com/aldeed/meteor-autoform

How can we get value from DOM Properties in JMeter?

I'm trying to record a scenario of SAP CRM.
But I have a problem due to that everytime I login SAP CRM generates a new hashed token and will be used in URL like below:
See Image 1 Here
I tried to check where is the information stored, and in firebug and I found it in DOM tab:
See Image 2 Here
Is there any way to get the value from this DOM Properties using Jmeter?
Usually the choices are in:
CSS/JQuery Extractor
XPath Extractor
Regular Expression Extractor
Choose the one, you're most familiar with. Usually it is Regular Expression Extractor, however parsing HTML with regular expressions is not a good idea, moreover you will be very sensitive to DOM changes (part of the element goes to next line, attributes change positions, etc.).
So I would recommend choosing between CSS and XPath, but choose them wisely. I.e. if the number of styles on the page is not too big - go for CSS, if there are a lot of styles but the DOM itself is not very complicated - choose XPath.

Populating some fields after selecting the element using Struts2-Dojo autocompleter

I am using sx tag i.e. struts-dojo-tag of struts 2 to autosuggest one field on one page. It is working fine. Now I want to populate other fields on the same page based on the selection of autosuggest field. I tried calling javascript on the above field on various events like onselect, onchange,etc with no success.
JSP code :
<sx:autocompleter autoComplete="true" listKey="id" listValue="brandName" name="brand.brandName" id="brandName" cssClass="textfield" list="brandList" onchange="populateInfo(this.value);"></sx:autocompleter>
here I want to autosuggest brandNames available and on selecting the brand, I want to populate data regarding the brand in some others fields. I tried calling java script function populateInfo(), but the function is not getting called.
Can you please help me out?
I think this problem can be solved by using select tag of struts2-jquery.
You can have a look in these showcase