New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not submit disabled <input> elements #248
Comments
Indeed, it looks like we're not dealing with this appropriately in MechanicalSoup. It will take some work to make us compliant with all the details of If you'd like to submit a PR, we would happily welcome it and can provide any guidance that you need. Otherwise, we'll get to this as soon as we can. Thanks for submitting this issue! |
I would like to work on this issue ! |
@rationa-kunal: thanks! Let us know if you need help, and don't hesitate to post drafts if you want feedback. |
I was thinking of adding an extra boolean variable in Form class as dev_option. If that is set to True then we can edit disabled values and if it is False we cant edit it. if i.has_attr("disabled") and not self.dev_op:
raise LinkNotFoundError("This is disabled field you have to set dev_op to true to edit this field " + `name)``` |
The most important point IMHO is that disabled fields should be ignored at submission time, unconditionally. Then, why not a feature to protect against edition of disabled fields. I don't think it'd be sane to allow editing disabled fields anyway (since they'll be ignored at submission time, there's no point editing them), but a feature to easily turn a disabled field to an enabled one would be nice. |
The problem with disabled fields is not the ability to edit them. It is that these items are currently considered when submitting the form. For example, if you have
Then MechanicalSoup already allows the user to edit things that are not meant to be editable in the page: the user of MechanicalSoup gets a completely editable BeautifulSoup object representing the HTML, and can do anything with it. It is not like an interactive browser where disabled elements must be explicitly disabled in the graphical user interface, to prevent users from doing mistakes. Here, the user is a programmer who can be expected to know what he or she is doing. |
So the idea is to just not edit the disabled inputs .... And drop the dev_op option ! |
There are some (disabled) fields that I want to edit, so leaving the option to edit them would be appreciated. This is desired by more than just me (https://stackoverflow.com/questions/9249996/mechanize-cannot-read-form-with-submitcontrol-that-is-disabled-and-has-no-value) |
Currently disabled fields are editable in MechanicalSoup, so @Quetzalcohuatl the behavior you expect is the current one (the question you link to is about mechanize, a different library). |
You're right. I post because I want to emphasize that I moved from mechanize to this library specifically for that feature. So if an edit comes, it should definitely be optional to ignore disabled elements. |
The change that would make the most sense to me is to simply not submit inputs that have the It would not be backwards compatible (e.g. if you were relying on submitting disabled inputs by default, then you would need to change your code to remove the For example, to enable all disabled inputs, you might write something like: form = br.get_current_form()
for item in form.form.find_all("input"):
if "disabled" in item.attrs:
del item.attrs["disabled"] Would it be useful to have a function that could add/remove the |
Your code @hemberger is a good solution to me. Didn't realize it was so simple. |
@hemberger : fully agree with you here. @Quetzalcohuatl : Indeed: keep in mind that MechanicalSoup is a very thin layer on top of requests and BeautifulSoup (both very solid libraries). Everything is possible by looking under the hood ;-). |
Closes MechanicalSoup#248. MechanicalSoup was incorrectly ignoring `disabled` attributes in form elements.
Closes #248. MechanicalSoup was incorrectly ignoring `disabled` attributes in form elements.
Closes MechanicalSoup#248. MechanicalSoup was incorrectly ignoring `disabled` attributes in form elements.
https://www.w3.org/TR/html52/sec-forms.html#element-attrdef-disabledformelements-disabled
MechanicalSoup ignores
disabled
attributes which should be fixed.Some additional notes: (from https://www.wufoo.com/html5/disabled-attribute/)
The text was updated successfully, but these errors were encountered: