Making hidden field visible when another field is used - django

I am trying to create a section in my models code that allows me to add a value only when the previous field is selected.
The goal of the code is to do the following
Have a null or blank option
Select an option from the tuple
Showing the new field option
The example of what I am looking to do is add a warranty to an item in my model. I am trying to make a date field (or a charfield that uses a date format) that only appears when an option is selected (i.e. a date field is available when the 30 day warranty is selected) otherwise the date field should be hidden (i.e. none is selected, so date field does not show)
Any suggestions, workarounds are welcomed
This is in Django Admin only

Related

Auto-fill form field

I have made a form field with drop down list with various choices(lets say A,B,C,D). The next field in the form is dependent on the option selected in the drop down list. How can I autofill the next field if option A is selected with a fixed value and make it charfield when other options are selected?
Edit: I have to autofill only one value when the first option i.e. option A is selected. So when the user clicks on A, it autofills 'yo'. Otherwise, in case of options B,C,D, it gives the option to enter some random word.

How to add new date format into Sitecore WebForms For Marketers (WFFM) date picker?

Is it possible in WFFM 2.4 to add own date format to date picker field? For design reasons we want format dd/MM/yy but I didn't find how to add another option to the the dropdown with available formats
Create a new item of template type /sitecore/templates/Web Forms for Marketers/Meta Data/Extended List Item in the following location:
/sitecore/system/Modules/Web Forms for Marketers/Settings/Meta data/Date Formats
It should then appear in the list of available formats.
Note however that although there is a "value" field on the item, it does not seem to be used, instead the droplist appears to use the item name. Just to be sure, set them all to the same value :)

Dropdown values customization in NetSuite

There is a custom record type configured in NS. It has a name and a free-form text field called full_name. Name is a standard field, full_name is a custom field. There is another record type which has a field of type List/Record with the previous type. On the form this field is present as drop-down. The drop-down show names of records. The goal is to show full names instead of names in the drop-down. Is it possible to mark somehow full_name field so it is available in the drop-down view instead of just name? Any ideas how to achieve this with NS?
Depending on your exact needs, it may make sense to add another custom field to the record containing your drop down. You can source this field from the full_name field on the custom record. This field does not need to store the value if it's only for display purposes.
Add a new field to the record containing the drop down
Set the type to be text
Name it appropriately
Under the 'Sourcing and Filtering' tab, set the source by field to the drop down
A field with type List/Record type can only show standard Name field. However, you can create a custom field dynamically on before record load of a user event script. Check the nlobjForm.addField. Please keep in mind that the value of it will not be saved. Saving the value is another story.

Create Template Custom Field Field in Sitecore

I want add a custom field in a Sitecore template.
Field will be a drop down of hours (1 -23) and used to show open and close time.
Ex: 8am to 7pm.
How can I add a custom field for that?
You can use a droplist field and set it's datasource to a folder that contains numbered items 1-23.
You could also just use a plain text field and optionally add a validator, or a date-time field if you actually want the time (+date) formatted.

Multi field and computed value

I need a solution for this problem:
I would like to have MultiField widget for a "value" field. This field should allow to input two values (two input widgets), and user should choose which of these values is to be saved (two checkbox widgets). However, one of these values must be recalculated with respect to other field's value.
I've taken this approach:
a MultiValueField with 4 fields:
class PriceDetailField(MultiValueField):
use_net = BooleanField(required=False)
net_value = DecimalField(required=False, decimal_places=2)
use_gross = BooleanField(required=False)
gross_value = DecimalField(required=False, decimal_places=2)
a MultiWidget:
class PriceDetailWidget(MultiWidget):
use_net = CheckboxInput()
net_value_widget = TextInput()
use_gross = CheckboxInput()
gross_value_widget = TextInput()
and a custom Form...
class PriceModelForm(ModelForm):
value = PriceDetailField()
...which overrides default model form for a model:
class Price(models.Model):
value = models.DecimalField(
max_digits=19,
decimal_places=2,
default=Decimal(0),
)
However, this solution seems to be messed up. In the form, I need to input all subfields (the MultiValueField subfields), otherwise "Please enter value" error appears (even though those fields are marked as required=False). Also,
I must recalculate the mentioned value upon a save, having returned a tuple from the field with information which checkbox was checked and the corresponding text value, then replace the tuple with the decimal value in clean_value method of form (also, saving the checkboxes state in temporary fields....). I think such a design is very weak.
The form should work both on its own and as inline (this means, the value of the field which is used to calculate the returned value can or cannot change during save).
Is such a thing even possible?
And the root of the problem: I want to store prices of items as net prices, but I would like to allow users to input them as net or gross prices, and then recalculate gross price to net price with respect to product's VAT tax level (since VAT is assigned to product or service, not to the price). A product can have many prices, so a price is backlinked to the product by a foreign key.
Cheers,
Tomek
The feature you're looking for on a MultiValueField (allowing the sub-fields to be required or not individually) is logged as a feature request on Django.
You could probably fix this for now by subclassing MultiValueField with a rewritten clean method based on the original and following suggestions from the bug report. You're not going to have a lot of the original MultiValueField left by that point though, and if you do, you should submit your patch to Django and put a note on the bug.
Ignoring for a moment the requiredness thing, have you written a compress method on your PriceDetailField? What does it look like? This is where you should be doing the work to turn your four sub-fields into a single field to save.