Validate one field based on other in ektron html form? - c#

Am working on Ektron 9.I have created an ektron html form with n number of fields.
Suppose i have a radio button list(Choice Field) following a text field.My choice radio button list has
two values Yes and No and the end user select one of those values.
I need to make the following text field required if the user select Yes in the choice radio button list.If selected No no need to make the text field required.
Is there any way to achieve the same by ektron custom validation?i have tried that but when am checking the fields the choice field not listing in the the insert field part of validation tab.
Is anything wrong with me ,if not anyone suggest a solution for this?

Custom validation like you describe is not possible with standard Ektron HTML forms. Your best bet would be to create an ASPX web form to achieve what you need.
There is the possibility of creating the HTML form, displaying it on an ASPX page and then adding your own custom javascript. However this is error prone as the HTML form and JS are very closely tied together. You are better off using an ASPX web form, and not an Ektron HTML form for this.

Related

C# .net core: Multiple ajax forms with hidden inputs with same ID

I have a web page with multiple separate tabs, all exist in DOM, switching between them is entirely client-side. Each tab contains an ajax form for editing data of a selected app user. For eg. first tab lets you edit name, surname, ..., second tab lets you edit address. Each tab has a save button and each time only properties of current tab are propagated to the DB. All works well :)
BUT, of course, each tab needs PK of the user (user.Id) in question. Its passed to controller via a hidden field
<input type="hidden" asp-for="Id" />, so HTML DOM contains more than one element with the same id and browsers complain.
I know that I could manually set the name/id of these input fields, and manually map them on the controller side, but model binder could do this for me, its nice and clean.
public async Task<IActionResult> EditGeneralData([Bind(GeneralDataBindFieldNames)]AppUser appUser)
Is there a nice & simple way to achieve this? Should I simply forget about the browser warning as I will be careful when/if using getElementById? Whats your take on this?
Yeah... not really the answer I was looking for, but it should suffice. It turns up that the content of these tabs is related to one another. So all the tabs cannot exist in the DOM at the same time, and switching between them cannot be entirely client side.
Now, tab click loads tab content on demand, so theres no multiple input fields in the DOM anymore. Only one tab at a time means only one input field at a time :)

Orchard Custom Form DropDownLists

After a bit of playing around with Orchards' Custom Forms module, i decided i wanted to use a dropdownlist to select a particular person with their email as the value for that selected option. While i was creating the form i couldn't see anyway you could set values to your options.
See below image for example:
Don't suppose anybody has come across this before or has a suggestion?
In your case I wouldn't worry about having different text and values for the fields. It's also potentially dangerous to make the recipient email an input of the HTML form.
The Custom Form Rule Event provided with Orchard gives you no way to look at the values of the content type created by the form. So, you're probably going to have to write your own. You should be able to base this on Orchard.CustomForms.Rules.CustomFormEvents.
Armed with this you'd be able to create new rules for each possible dropdown value and set the email address in the action for each rule.

Don't post back textbox

I have a fairly complex form (user control actually) with one textbox control on it that needs to NOT post back. Is there a way to remove a control from the post? Yes, this textbox is editable.
More info: This is for a credit card processing form, so the "final" submit will post to another site's page. However, prior to this there is plenty of server-side processing that goes on. I know that I can move the the credit card number text box to another page - but this requirement came very late and I'll trying to not have to re-work a lot of things.
The easiest way would be to use an html input as opposed to an ASP TextBox. These are not accessible from code if runat="server" is not set on them.
Or use the viewstate property (http://msdn.microsoft.com/en-us/library/system.web.ui.control.enableviewstate.aspx)
So the situation is that you have a form that is rendered in the user's browser with an action pointing to a different site and you need to make sure that one of the form fields will not be sent when the form is submitted.
Sounds to me like you cannot in that case make absolutely sure that the value is not posted. There are many different possible ways to solve this using javascript (disable input, clear value, etc before submit) but if scripting is turned off I think you're out of luck.
But since you can prepare for sending the form to the other server (change action on form or enable button with PostBackUrl), I guess you could also then set the Enabled property on the textbox to false. That would mean that it can no longer be edited on the final page beforr posting to the other server. Or you could hide the textbox a (so it's not renered at all) and show the field as a label or literal instead.
But even then you still have to somehow make sure the secret value is not included in the viewstate of the form. Which it will be in case you use a label or literal. And also for a textbox that was disabled or hidden on the last postback. Normally the viewstate is just a base64 encoded string so it would be trivial to find the credit card number from there. You could probably fix this by turning off viewstate for the control in question (or even for the whole page) in the last post back to your page before setting the form up for posting to the other server.
If you cannot tell for sure which will be the last postback to your server, then I think you're out of luck without more significant changes. Sorry to be a downer. Some seemingly trivial things are just hard with Asp.Net web forms.
Maybe you could add a separate page that you populate with just the data that you need to send to the other server and have that a sort of "Confirmation page". In that page you could turn off viewstate, show all the data summarized (using labels and literals etc) and the actual data to post could be included in the form as hidden fields. Then that form would post to the other server when the user "Confirms".

formatting an asp:TextBox with thousand and decimal separators

I have done this many times in PHP using JS but being new to webforms I'm really struggling on this one...
OKay, on my form I have an "asp:TextBox" that I want the user to enter an amount of money into.
What I would like is once the user moves out of the "asp:TextBox", I would like it formatted like ###,###,###.## for display purposes. I dont need the currency symbol.
Can anyone give any guidance on how to do this and also is the formatting submitted along with the value on submit as standard or is that stripped away and only used for user display purposes?
Thanks
Paul
You can add client-side functionality to webform controls by adding attributes to them before they get rendered. You can add a property to the textbox in your code:
myTextbox.Attributes.Add("onblur", "myJavascriptFormattingFunction();");
You can take a look at this article for other methods of linking webcontrols to javascript.
Whatever value is in the textbox itself is what will be submitted, so if you add commas and whatnot, then they will be submitted.

Creating a Search interface in ASP.NET MVC - C#

The above is concept of a search interface I want to build in ASP.net MVC. when user clicks on the '+' button, it should create a row text filters or date filters. Does jQuery offer me this flexibility or are there any such UI frameworks which would help me achieve this? There is a search button, not shown, which when clicked should post back and obtain results and display the results
It sounds like you want to create dynamic form. Just use the Jquery .append to add new elements to your form.
$("#myform").append("<input type='text' name='textfield'>")
A little difficult to visualise what you are talking about as it doesn't show in the question.
But if I understand your question then you want to click on a button and show some filter fields right?
This is do-able not only in jQuery but in just standard javascript. All you need to do is unhide the filter elements.
jQuery will give you a nice way to scroll it open though and then you could do a partial post back and just return the results or partial view.
$("#divFilters").slideDown(300);
The code above will open your div.
Or you could jQuery a partial postback, return RenderPartial from your controller and replace the html in a div somewhere. The RenderPartail would be a partial view with your filters in it. Easier to extend at a later date too I'd have thought.
Is this what you were after?

Categories

Resources